Struct MutableSnapshot

Source
pub struct MutableSnapshot<T: Debug>(pub MutableOnDemand<Option<SharedSnapshot<T>>>);
Expand description

Use this type for fields in structs that are to store the Snapshot, typically behind an OwnShared.

Note that the resource itself is behind another OwnShared to allow it to be used without holding any kind of lock, hence without blocking updates while it is used.

Tuple Fields§

§0: MutableOnDemand<Option<SharedSnapshot<T>>>

Implementations§

Source§

impl<T: Debug> MutableSnapshot<T>

Source

pub fn new() -> Self

Create a new instance of this type.

Useful in case Default::default() isn’t working for some reason.

Source

pub fn force_refresh<E>( &self, open: impl FnOnce() -> Result<Option<(SystemTime, T)>, E>, ) -> Result<(), E>

Refresh state forcefully by re-opening the resource. Note that open() returns None if the resource isn’t present on disk, and that it’s critical that the modified time is obtained before opening the resource.

Source

pub fn recent_snapshot<E>( &self, current_modification_time: impl FnMut() -> Option<SystemTime>, open: impl FnOnce() -> Result<Option<T>, E>, ) -> Result<Option<SharedSnapshot<T>>, E>

Assure that the resource in state is up-to-date by comparing the current_modification_time with the one we know in state and by acting accordingly. Returns the potentially updated/reloaded resource if it is still present on disk, which then represents a snapshot that is up-to-date in that very moment, or None if the underlying file doesn’t exist.

Note that even though this is racy, each time a request is made there is a chance to see the actual state.

Methods from Deref<Target = MutableOnDemand<Option<SharedSnapshot<T>>>>§

Source

pub unsafe fn make_read_guard_unchecked(&self) -> RwLockReadGuard<'_, R, T>

Available on crate feature parallel only.

Creates a new RwLockReadGuard without checking if the lock is held.

§Safety

This method must only be called if the thread logically holds a read lock.

This function does not increment the read count of the lock. Calling this function when a guard has already been produced is undefined behaviour unless the guard was forgotten with mem::forget.

Source

pub unsafe fn make_write_guard_unchecked(&self) -> RwLockWriteGuard<'_, R, T>

Available on crate feature parallel only.

Creates a new RwLockReadGuard without checking if the lock is held.

§Safety

This method must only be called if the thread logically holds a write lock.

Calling this function when a guard has already been produced is undefined behaviour unless the guard was forgotten with mem::forget.

Source

pub fn read(&self) -> RwLockReadGuard<'_, R, T>

Available on crate feature parallel only.

Locks this RwLock with shared read access, blocking the current thread until it can be acquired.

The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns.

Note that attempts to recursively acquire a read lock on a RwLock when the current thread already holds one may result in a deadlock.

Returns an RAII guard which will release this thread’s shared access once it is dropped.

Source

pub fn try_read(&self) -> Option<RwLockReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with shared read access.

If the access could not be granted at this time, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

This function does not block.

Source

pub fn write(&self) -> RwLockWriteGuard<'_, R, T>

Available on crate feature parallel only.

Locks this RwLock with exclusive write access, blocking the current thread until it can be acquired.

This function will not return while other writers or other readers currently have access to the lock.

Returns an RAII guard which will drop the write access of this RwLock when dropped.

Source

pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to lock this RwLock with exclusive write access.

If the lock could not be acquired at this time, then None is returned. Otherwise, an RAII guard is returned which will release the lock when it is dropped.

This function does not block.

Source

pub fn is_locked(&self) -> bool

Available on crate feature parallel only.

Checks whether this RwLock is currently locked in any way.

Source

pub fn is_locked_exclusive(&self) -> bool

Available on crate feature parallel only.

Check if this RwLock is currently exclusively locked.

Source

pub unsafe fn force_unlock_read(&self)

Available on crate feature parallel only.

Forcibly unlocks a read lock.

This is useful when combined with mem::forget to hold a lock without the need to maintain a RwLockReadGuard object alive, for example when dealing with FFI.

§Safety

This method must only be called if the current thread logically owns a RwLockReadGuard but that guard has be discarded using mem::forget. Behavior is undefined if a rwlock is read-unlocked when not read-locked.

Source

pub unsafe fn force_unlock_write(&self)

Available on crate feature parallel only.

Forcibly unlocks a write lock.

This is useful when combined with mem::forget to hold a lock without the need to maintain a RwLockWriteGuard object alive, for example when dealing with FFI.

§Safety

This method must only be called if the current thread logically owns a RwLockWriteGuard but that guard has be discarded using mem::forget. Behavior is undefined if a rwlock is write-unlocked when not write-locked.

Source

pub unsafe fn raw(&self) -> &R

Available on crate feature parallel only.

Returns the underlying raw reader-writer lock object.

Note that you will most likely need to import the RawRwLock trait from lock_api to be able to call functions on the raw reader-writer lock.

§Safety

This method is unsafe because it allows unlocking a mutex while still holding a reference to a lock guard.

Source

pub fn data_ptr(&self) -> *mut T

Available on crate feature parallel only.

Returns a raw pointer to the underlying data.

This is useful when combined with mem::forget to hold a lock without the need to maintain a RwLockReadGuard or RwLockWriteGuard object alive, for example when dealing with FFI.

§Safety

You must ensure that there are no data races when dereferencing the returned pointer, for example if the current thread logically owns a RwLockReadGuard or RwLockWriteGuard but that guard has been discarded using mem::forget.

Source

pub unsafe fn force_unlock_read_fair(&self)

Available on crate feature parallel only.

Forcibly unlocks a read lock using a fair unlock protocol.

This is useful when combined with mem::forget to hold a lock without the need to maintain a RwLockReadGuard object alive, for example when dealing with FFI.

§Safety

This method must only be called if the current thread logically owns a RwLockReadGuard but that guard has be discarded using mem::forget. Behavior is undefined if a rwlock is read-unlocked when not read-locked.

Source

pub unsafe fn force_unlock_write_fair(&self)

Available on crate feature parallel only.

Forcibly unlocks a write lock using a fair unlock protocol.

This is useful when combined with mem::forget to hold a lock without the need to maintain a RwLockWriteGuard object alive, for example when dealing with FFI.

§Safety

This method must only be called if the current thread logically owns a RwLockWriteGuard but that guard has be discarded using mem::forget. Behavior is undefined if a rwlock is write-unlocked when not write-locked.

Source

pub fn try_read_for( &self, timeout: <R as RawRwLockTimed>::Duration, ) -> Option<RwLockReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with shared read access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

Source

pub fn try_read_until( &self, timeout: <R as RawRwLockTimed>::Instant, ) -> Option<RwLockReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with shared read access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

Source

pub fn try_write_for( &self, timeout: <R as RawRwLockTimed>::Duration, ) -> Option<RwLockWriteGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with exclusive write access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the exclusive access when it is dropped.

Source

pub fn try_write_until( &self, timeout: <R as RawRwLockTimed>::Instant, ) -> Option<RwLockWriteGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with exclusive write access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the exclusive access when it is dropped.

Source

pub fn read_recursive(&self) -> RwLockReadGuard<'_, R, T>

Available on crate feature parallel only.

Locks this RwLock with shared read access, blocking the current thread until it can be acquired.

The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns.

Unlike read, this method is guaranteed to succeed without blocking if another read lock is held at the time of the call. This allows a thread to recursively lock a RwLock. However using this method can cause writers to starve since readers no longer block if a writer is waiting for the lock.

Returns an RAII guard which will release this thread’s shared access once it is dropped.

Source

pub fn try_read_recursive(&self) -> Option<RwLockReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with shared read access.

If the access could not be granted at this time, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

This method is guaranteed to succeed if another read lock is held at the time of the call. See the documentation for read_recursive for details.

This function does not block.

Source

pub fn try_read_recursive_for( &self, timeout: <R as RawRwLockTimed>::Duration, ) -> Option<RwLockReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with shared read access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

This method is guaranteed to succeed without blocking if another read lock is held at the time of the call. See the documentation for read_recursive for details.

Source

pub fn try_read_recursive_until( &self, timeout: <R as RawRwLockTimed>::Instant, ) -> Option<RwLockReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with shared read access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

Source

pub unsafe fn make_upgradable_guard_unchecked( &self, ) -> RwLockUpgradableReadGuard<'_, R, T>

Available on crate feature parallel only.

Creates a new RwLockUpgradableReadGuard without checking if the lock is held.

§Safety

This method must only be called if the thread logically holds an upgradable read lock.

This function does not increment the read count of the lock. Calling this function when a guard has already been produced is undefined behaviour unless the guard was forgotten with mem::forget.

Source

pub fn upgradable_read(&self) -> RwLockUpgradableReadGuard<'_, R, T>

Available on crate feature parallel only.

Locks this RwLock with upgradable read access, blocking the current thread until it can be acquired.

The calling thread will be blocked until there are no more writers or other upgradable reads which hold the lock. There may be other readers currently inside the lock when this method returns.

Returns an RAII guard which will release this thread’s shared access once it is dropped.

Source

pub fn try_upgradable_read(&self) -> Option<RwLockUpgradableReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with upgradable read access.

If the access could not be granted at this time, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

This function does not block.

Source

pub fn try_upgradable_read_for( &self, timeout: <R as RawRwLockTimed>::Duration, ) -> Option<RwLockUpgradableReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with upgradable read access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

Source

pub fn try_upgradable_read_until( &self, timeout: <R as RawRwLockTimed>::Instant, ) -> Option<RwLockUpgradableReadGuard<'_, R, T>>

Available on crate feature parallel only.

Attempts to acquire this RwLock with upgradable read access until a timeout is reached.

If the access could not be granted before the timeout expires, then None is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

Trait Implementations§

Source§

impl<T: Debug + Debug> Debug for MutableSnapshot<T>

Source§

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

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

impl<T: Default + Debug> Default for MutableSnapshot<T>

Source§

fn default() -> MutableSnapshot<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Debug> Deref for MutableSnapshot<T>

Source§

type Target = RwLock<RawRwLock, Option<Arc<Snapshot<T>>>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T> !Freeze for MutableSnapshot<T>

§

impl<T> !RefUnwindSafe for MutableSnapshot<T>

§

impl<T> Send for MutableSnapshot<T>
where T: Sync + Send,

§

impl<T> Sync for MutableSnapshot<T>
where T: Sync + Send,

§

impl<T> Unpin for MutableSnapshot<T>

§

impl<T> UnwindSafe for MutableSnapshot<T>
where T: RefUnwindSafe,

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.