//! A token's REACH — the databases one call may touch (design 3.8, B1).//!//! A personal token reaches every database on this server its owner owns,//! Mine first; a seat or place token reaches its one file. A [`Ctx`] stays//! bound to one file; the wrapper that fans a call out//! (`cotton_server::mcp::places`) builds one `Ctx` per file it touches, each//! [`Ctx::within`] the same `Reach`.//!//! What an assistant reads says DATABASE: the wrapper's argument is//! `database`, a merged row carries `database` and `databaseId`. The Rust//! names here kept the word they landed with (place, `ReachFile`).//!//! [`Ctx`]: crate::mcp::dispatch::Ctx//! [`Ctx::within`]: crate::mcp::dispatch::Ctx::within/// One database a token reaches.#[derive(Debug, Clone, PartialEq, Eq)]pubstructReachFile {/// The file's id — its workspace id, what a caller passes as `database`/// and what each merged row carries as `databaseId`.pub id: String,/// What the owner calls it ("Mine", "the product team's place").pub name: String,/// Is this the owner's personal database?pub is_mine: bool,}/// Why a reach is what it is.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubenumReachBasis {/// The registry names the token's file as its owner's personal row: every/// database that owner owns.Personal,/// A seat or place token, a worker, an assistant run or the phone: its/// one file, never Mine unless that file is Mine.OneFile,}/// The files one call may touch, Mine first.#[derive(Debug, Clone, PartialEq, Eq)]pubstructReach {pub files: Vec<ReachFile>,pub basis: ReachBasis,}/// A `database` outside reach, or one that does not exist.////// ONE answer for both, so a seat token cannot probe for databases it does/// not reach by telling the two apart.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubstructNoSuchPlace;implNoSuchPlace {pubconst SENTENCE: &'static str = "no such database";}impl std::fmt::DisplayforNoSuchPlace {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(Self::SENTENCE) }}impl std::error::ErrorforNoSuchPlace {}implReach {/// One file and nothing else.pubfn only(file: ReachFile) -> Reach {Reach { files: vec![file], basis: ReachBasis::OneFile, } }/// The file a `database` argument names, by its id.pubfn place(&self, place: &str) -> Result<&ReachFile, NoSuchPlace> {ifletSome(file) = self.files.iter().find(|file| file.id == place) { returnOk(file); }if place.eq_ignore_ascii_case("personal") { returnself.mine().ok_or(NoSuchPlace); }letmut matches = self.files.iter().filter(|file| file.name == place);match (matches.next(), matches.next()) { (Some(file), None) => Ok(file), _ => Err(NoSuchPlace) } }/// The owner's personal database, when this reach holds it.pubfn mine(&self) -> Option<&ReachFile> {self.files.iter().find(|file| file.is_mine) }}#[cfg(test)]#[path = "places_tests.rs"]mod tests;