Skip to main content

FileTable

Struct FileTable 

Source
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>

Source

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.

Source

pub fn max_bytes(self, max: usize) -> Self

The most the file may hold, in bytes, read or written. Default DEFAULT_MAX_BYTES.

Source

pub fn path(&self) -> &Path

The file.

Trait Implementations§

Source§

impl<T, C: Codec> Debug for FileTable<T, C>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, C> Table<T> for FileTable<T, C>
where T: Keyed + Clone + Send + Walk + FromWalk, C: Codec,

Source§

fn load(&self) -> Result<Snapshot<T>, SourceError>

Every record, with the revision they are at. Read more
Source§

fn changes_since( &self, since: Revision, ) -> Result<Option<Snapshot<T>>, SourceError>

The records again when the table is no longer at revision since, else None. Read more
Source§

fn put(&self, record: T) -> Result<(), SourceError>

Adds record, or replaces the one with the same Keyed::key. Read more
Source§

fn update(&self, make: &mut Update<'_, T>) -> Result<(), SourceError>

Reads the records, lets make decide from them what to put (None puts nothing), and puts it. Read more
Source§

fn remove(&self, key: &str) -> Result<bool, SourceError>

Removes the record with this key; true when there was one. Read more
Source§

fn remove_where( &self, condition: &mut dyn FnMut(&T) -> bool, ) -> Result<usize, SourceError>

Removes every record condition holds for, and answers how many went. Read more
Source§

fn get(&self, key: &str) -> Result<Option<T>, SourceError>
where T: Keyed,

The record with this key, or None. Read more
Source§

fn update_one( &self, key: &str, make: &mut UpdateOne<'_, T>, ) -> Result<(), SourceError>
where T: Keyed,

Like update, for the one record with this key: make is given that record (or None) as the table holds it under its lock, and what it returns is put. Read more

Auto Trait Implementations§

§

impl<T, C> !Freeze for FileTable<T, C>

§

impl<T, C> RefUnwindSafe for FileTable<T, C>
where C: RefUnwindSafe,

§

impl<T, C> Send for FileTable<T, C>
where C: Send,

§

impl<T, C> Sync for FileTable<T, C>
where C: Sync,

§

impl<T, C> Unpin for FileTable<T, C>
where C: Unpin,

§

impl<T, C> UnsafeUnpin for FileTable<T, C>
where C: UnsafeUnpin,

§

impl<T, C> UnwindSafe for FileTable<T, C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.