Skip to main content

Reloading

Struct Reloading 

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

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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

Removes the record with key; true when there was one.

§Errors

Returns an error when the table cannot be read or refuses the removal.

Trait Implementations§

Source§

impl<T> Debug for Reloading<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Reloading<T>

§

impl<T> !RefUnwindSafe for Reloading<T>

§

impl<T> !UnwindSafe for Reloading<T>

§

impl<T> Send for Reloading<T>
where T: Send,

§

impl<T> Sync for Reloading<T>
where T: Send,

§

impl<T> Unpin for Reloading<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Reloading<T>

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.