Cotton code
64 lines · 2.7 KB · RustRaw
//! The file a read or a write runs over, as ONE shape: this device's copy.//!//! Every `read.*` query takes a [`ReadFile`]: the driver and the four facts//! every query used off the replica, from the writer ([`ReadFile::of`]) or a//! read connection ([`ReadFile::of_reader`]).use cotton_client::replica::{ReadReplica, Replica};use cotton_store::driver::Driver;use cotton_store::file_identity::FileIdentity;/// What a query sees. The field names are the replica's, on purpose: eighty/// query functions read `file.driver` and `file.workspace_id`.pub struct ReadFile<'a> {    pub driver: &'a Driver,    pub workspace_id: &'a str,    /// Which file this is and the namespace its derived ids are made under,    /// read once when the file was opened.    pub identity: &'a FileIdentity,    pub owner_id: &'a str,    /// This device's own id, the author of every op its copy mints.    pub device_id: &'a str,    /// WHICH RAIL answered — the word a screen says for this device's copy.    ///    /// **This is where the file's PATH used to be**, and the path is gone on    /// purpose. `read.activity` printed it on the transparency screen, so a    /// phone standing beside a Mac drew that Mac's home folder    /// (`/Users/<name>/CottonDB/client/<ws>/replica.db`) — another machine's    /// filesystem, on a screen that only ever wanted to say WHICH FILE YOU    /// ARE LOOKING AT. The answer to that is this word. No filesystem path    /// crosses the boundary to a screen, and `activity_tests` holds that over    /// the whole of `read.activity`'s answer rather than over one key.    pub held: FileHeld,}/// How this process is holding the file it is reading — declared once in/// `cotton_tools::rails`, where the `activity` table's record reads it too.pub use cotton_tools::rails::FileHeld;impl<'a> ReadFile<'a> {    /// A replica, seen as a file.    pub fn of(replica: &'a Replica) -> ReadFile<'a> {        ReadFile {            driver: &replica.driver,            workspace_id: &replica.workspace_id,            identity: &replica.identity,            owner_id: &replica.owner_id,            device_id: &replica.device_id,            held: FileHeld::Replica,        }    }    /// A replica's READ connection, seen as a file — what every screen's read    /// runs over on a device holding a copy (`ClientController::with_file`).    pub fn of_reader(reader: &'a ReadReplica) -> ReadFile<'a> {        ReadFile {            driver: &reader.driver,            workspace_id: &reader.workspace_id,            identity: &reader.identity,            owner_id: &reader.owner_id,            device_id: &reader.device_id,            held: FileHeld::Replica,        }    }}