StoreLock

Struct StoreLock 

Source
pub struct StoreLock<T: ?Sized>(/* private fields */);
Expand description

Records messages delivered via Listener by mutating a value which implements Store.

This value is referred to as the “state”, and it is kept inside a mutex.

§Generic parameters

  • T is the type of the state, which should implement Store.

Implementations§

Source§

impl<T> StoreLock<T>

Source

pub fn new(initial_state: T) -> Self

Construct a new StoreLock with the given initial state.

Source§

impl<T: ?Sized> StoreLock<T>

Source

pub fn listener(&self) -> StoreLockListener<T>

Returns a Listener which delivers messages to this.

Source

pub fn lock(&self) -> impl DerefMut<Target = T> + use<'_, T>

Locks and returns access to the state.

Callers should be careful to hold the lock for a very short time (e.g. only to copy or take the data) or to do so only while messages will not be arriving. Otherwise, poor performance or deadlock may result.

§Panics

If it is called while the same thread has already acquired the lock, it may panic or hang, depending on the mutex implementation in use.

Source

pub fn take(&self) -> T
where T: Sized + Default,

Replaces the current state with T::default() and returns it.

This is not more powerful than lock(), but it offers the guarantee that it will hold the lock for as little time as possible. It is equivalent to:

let replacement = T::default();
mem::replace(&mut *self.lock(), replacement)
§Panics

If it is called while the same thread has already acquired the lock, it may panic or hang, depending on the mutex implementation in use.

Source

pub fn receive<M>(&self, messages: &[M])
where T: Store<M>,

Delivers messages like self.listener().receive(messages), but without creating a temporary listener.

§Panics

If it is called while the same thread has already acquired the lock, it may panic or hang, depending on the mutex implementation in use.

Trait Implementations§

Source§

impl<T: ?Sized + Debug> Debug for StoreLock<T>

Source§

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

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

impl<T: Default + ?Sized> Default for StoreLock<T>

Source§

fn default() -> StoreLock<T>

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

impl<T: ?Sized> Pointer for StoreLock<T>

Source§

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

Produces an address which is the same for this StoreLock and its associated StoreLockListeners.

Auto Trait Implementations§

§

impl<T> Freeze for StoreLock<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for StoreLock<T>

§

impl<T> Send for StoreLock<T>
where T: Send + ?Sized,

§

impl<T> Sync for StoreLock<T>
where T: Send + ?Sized,

§

impl<T> Unpin for StoreLock<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for StoreLock<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.

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.