pub struct Reloading<T> { /* private fields */ }Expand description
A table with its latest Snapshot cached, refreshed through
Table::changes_since on every use, so a write by anyone else is seen without
reopening.
Every snapshot is checked with the validation given to new; a table
that has become unreadable or invalid is an error, never a stale answer.
Implementations§
Source§impl<T: Keyed + Clone> Reloading<T>
impl<T: Keyed + Clone> Reloading<T>
Sourcepub fn new(
table: Arc<dyn Table<T>>,
validate: impl Fn(&[T]) -> Result<(), SourceError> + Send + Sync + 'static,
) -> Result<Self, SourceError>
pub fn new( table: Arc<dyn Table<T>>, validate: impl Fn(&[T]) -> Result<(), SourceError> + Send + Sync + 'static, ) -> Result<Self, SourceError>
Loads table once, checking it with validate.
§Errors
Returns an error when the table cannot be loaded or validate refuses it.
Sourcepub fn read<R>(&self, read: impl FnOnce(&[T]) -> R) -> Result<R, SourceError>
pub fn read<R>(&self, read: impl FnOnce(&[T]) -> R) -> Result<R, SourceError>
Runs read over the current records.
§Errors
Returns an error when the table changed and can no longer be read or is invalid.
Sourcepub fn put_with<R>(
&self,
make: impl FnOnce(&[T]) -> Result<(T, R), SourceError>,
) -> Result<R, SourceError>
pub fn put_with<R>( &self, make: impl FnOnce(&[T]) -> Result<(T, R), SourceError>, ) -> Result<R, SourceError>
Makes one record from the current ones and puts it, or puts nothing when make
refuses or the records with it would be invalid.
§Errors
Returns an error when the table cannot be read, make refuses, the result is
invalid, or the table refuses the put (SourceError::ReadOnly for a read-only
table).
Sourcepub fn get(&self, key: &str) -> Result<Option<T>, SourceError>
pub fn get(&self, key: &str) -> Result<Option<T>, SourceError>
The record with key, read from the table itself and checked alone: neither the
cache nor the other records are touched, so a record that cannot be read or fails
validate is an error for its own key only.
§Errors
Returns an error when the table or the record cannot be read, or the record is invalid.
Sourcepub fn update_one<R>(
&self,
key: &str,
make: impl FnOnce(Option<&T>) -> Result<(Option<T>, R), SourceError>,
) -> Result<R, SourceError>
pub fn update_one<R>( &self, key: &str, make: impl FnOnce(Option<&T>) -> Result<(Option<T>, R), SourceError>, ) -> Result<R, SourceError>
Like put_with, for the one record with key: make is
given it (or None) as the table reads it under its lock, and returns the record to
put (None puts nothing) and a result. Only that record is read and checked, so
one that cannot be read is an error for its own key only, and the cost does not
grow with the table.
§Errors
Returns an error when the table or the record cannot be read, make refuses, the
record or the result is invalid or has another key, or the table refuses the put.