pub struct FileTable<T, C> { /* private fields */ }Expand description
A table of T kept in one private file: a document with one key, section, holding the
list of records, written by codec C.
Records cross through their guatiao derives (ToValue/FromValue, which also stream)
and guatiao-serde’s bridge, with no tree in between. A self-describing format reads a
byte string back only as the codec’s [Presentation] spells it.
A missing file is an empty table. Every read compares the file’s Stamp, so a write by
another process is a new revision; a file that is unreadable, oversized or invalid is an
error, never a stale answer. Errors never contain file contents.
A read-modify-write (put, remove, update) holds an exclusive operating-system lock
on a file beside the table, <path>.lock, from the read to the write, in this process and
in any other that uses it, so no update is lost and update computes its change from the
records it replaces. The lock file is left in place and holds nothing. Reads take no lock:
the file is replaced whole.
Implementations§
Source§impl<T, C> FileTable<T, C>
impl<T, C> FileTable<T, C>
Sourcepub fn new(
path: impl Into<PathBuf>,
section: impl Into<String>,
codec: C,
) -> Self
pub fn new( path: impl Into<PathBuf>, section: impl Into<String>, codec: C, ) -> Self
The table under section in the file at path, which need not exist yet, written
with codec. Nothing is read until the table is used.
Sourcepub fn max_bytes(self, max: usize) -> Self
pub fn max_bytes(self, max: usize) -> Self
The most the file may hold, in bytes, read or written. Default DEFAULT_MAX_BYTES.
Trait Implementations§
Source§impl<T, C> Table<T> for FileTable<T, C>
impl<T, C> Table<T> for FileTable<T, C>
Source§fn load(&self) -> Result<Snapshot<T>, SourceError>
fn load(&self) -> Result<Snapshot<T>, SourceError>
Source§fn changes_since(
&self,
since: Revision,
) -> Result<Option<Snapshot<T>>, SourceError>
fn changes_since( &self, since: Revision, ) -> Result<Option<Snapshot<T>>, SourceError>
Source§fn update(&self, make: &mut Update<'_, T>) -> Result<(), SourceError>
fn update(&self, make: &mut Update<'_, T>) -> Result<(), SourceError>
make decide from them what to put (None puts nothing),
and puts it. Read moreSource§fn remove(&self, key: &str) -> Result<bool, SourceError>
fn remove(&self, key: &str) -> Result<bool, SourceError>
true when there was one. Read moreSource§fn remove_where(
&self,
condition: &mut dyn FnMut(&T) -> bool,
) -> Result<usize, SourceError>
fn remove_where( &self, condition: &mut dyn FnMut(&T) -> bool, ) -> Result<usize, SourceError>
condition holds for, and answers how many went. Read more