pub trait Table<T>: Send + Sync {
// Required method
fn load(&self) -> Result<Snapshot<T>, SourceError>;
// Provided methods
fn changes_since(
&self,
since: Revision,
) -> Result<Option<Snapshot<T>>, SourceError> { ... }
fn put(&self, record: T) -> Result<(), SourceError> { ... }
fn remove(&self, key: &str) -> Result<bool, SourceError> { ... }
fn update(&self, make: &mut Update<'_, T>) -> Result<(), SourceError> { ... }
fn get(&self, key: &str) -> Result<Option<T>, SourceError>
where T: Keyed { ... }
fn update_one(
&self,
key: &str,
make: &mut UpdateOne<'_, T>,
) -> Result<(), SourceError>
where T: Keyed { ... }
fn remove_where(
&self,
condition: &mut dyn FnMut(&T) -> bool,
) -> Result<usize, SourceError>
where T: Keyed { ... }
}Expand description
Where a provider’s records of type T come from, and optionally go to.
Implementations are free to keep records anywhere. They must be cheap to ask for changes:
Reloading calls changes_since on every use.
Required Methods§
Provided Methods§
Sourcefn changes_since(
&self,
since: Revision,
) -> Result<Option<Snapshot<T>>, SourceError>
fn changes_since( &self, since: Revision, ) -> Result<Option<Snapshot<T>>, SourceError>
Sourcefn put(&self, record: T) -> Result<(), SourceError>
fn put(&self, record: T) -> Result<(), SourceError>
Adds record, or replaces the one with the same Keyed::key.
§Errors
SourceError::ReadOnly by default.
Sourcefn remove(&self, key: &str) -> Result<bool, SourceError>
fn remove(&self, key: &str) -> Result<bool, SourceError>
Removes the record with this key; true when there was one.
§Errors
SourceError::ReadOnly by default.
Sourcefn update(&self, make: &mut Update<'_, T>) -> Result<(), SourceError>
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.
A table shared with another process overrides this to hold a lock from the read to
the write, so make always sees the records its result replaces into. The default
is a read and a put with nothing between them, which is as safe as the table’s own
put.
§Errors
When the table cannot be read, make refuses, or the put fails
(SourceError::ReadOnly for a read-only table).
Sourcefn get(&self, key: &str) -> Result<Option<T>, SourceError>where
T: Keyed,
fn get(&self, key: &str) -> Result<Option<T>, SourceError>where
T: Keyed,
The record with this key, or None.
The default loads every record and picks one, so a table that can find a record by its key (a database, an API, a record per file) overrides it: then a record that cannot be read is an error for its own key only, and a caller that serves one person at a time pays for one record.
§Errors
When the table, or this record, cannot be read.
Sourcefn update_one(
&self,
key: &str,
make: &mut UpdateOne<'_, T>,
) -> Result<(), SourceError>where
T: Keyed,
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.
The default is update with the other records left out of
make’s view; override it with get to read one record.
§Errors
When the table or this record cannot be read, make refuses, or the put fails.
Sourcefn remove_where(
&self,
condition: &mut dyn FnMut(&T) -> bool,
) -> Result<usize, SourceError>where
T: Keyed,
fn remove_where(
&self,
condition: &mut dyn FnMut(&T) -> bool,
) -> Result<usize, SourceError>where
T: Keyed,
Removes every record condition holds for, and answers how many went.
The default loads the records and removes each through remove, a
write apiece, so a table that rewrites itself on every write overrides it to remove
them all in one. Nothing matching writes nothing, so a read-only table answers 0.
§Errors
When the table cannot be read or a removal fails (SourceError::ReadOnly for a
read-only table holding a matching record).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".