Struct wnf::DataAccessor

source ·
pub struct DataAccessor<'a, T>
where T: ?Sized,
{ /* private fields */ }
Available on crate feature subscribe only.
Expand description

A handle to state data passed to state listeners

Listeners receive a DataAccessor<'a, T> in their StateListener::call method. It can be used to obtain the state data at the time the update took place.

The lifetime parameter 'a ties a DataAccessor<'a, T> to the lifetime of the state data, which is only valid within the scope of the call to the listener.

Implementations§

source§

impl<'a, T> DataAccessor<'a, T>
where T: ?Sized,

source

pub const fn cast<U>(self) -> DataAccessor<'a, U>
where U: ?Sized,

Casts the data type of this DataAccessor<'a, T> to a different type U

The returned DataAccessor<'a, U> represents the same underlying data, but treats them as being of a different type U.

source

pub const fn change_stamp(self) -> ChangeStamp

Queries the change stamp of this DataAccessor<'_, T>

The change stamp returned by this method is the change stamp of the underlying state for the update that caused the listener call to which this DataAccessor<'_, T> was passed. Note that in contrast to OwnedState::change_stamp or BorrowedState::change_stamp, this does not involve an OS call.

source§

impl<T> DataAccessor<'_, T>
where T: Read<T>,

source

pub fn get(self) -> Result<T>

Queries the data of this DataAccessor<'_, T>

This produces an owned T on the stack and hence requires T: Sized. In order to produce a Box<T> for T: ?Sized, use the get_boxed method.

This returns the data of the accessor without a change stamp. In order to query both the data and the change stamp, use the query method.

The data returned by this method are the data of the underlying state for the update that caused the listener call to which this DataAccessor<'_, T> was passed. Note that in contrast to OwnedState::get or BorrowedState::get, this does not involve an OS call.

§Errors

Returns an error if the queried data is not a valid T

source

pub fn query(self) -> Result<StampedData<T>>

Queries the data of this DataAccessor<'_, T> together with their change stamp

This produces an owned T on the stack and hence requires T: Sized. In order to produce a Box<T> for T: ?Sized, use the query_boxed method.

This returns the data of the accessor together with their change stamp as a StampedData<T>. In order to only query the data, use the get method.

The data returned by this method are the data of the underlying state for the update that caused the listener call to which this DataAccessor<'_, T> was passed. Note that in contrast to OwnedState::query or BorrowedState::query, this does not involve an OS call.

§Errors

Returns an error if the queried data is not a valid T

source§

impl<T> DataAccessor<'_, T>
where T: Read<Box<T>> + ?Sized,

source

pub fn get_boxed(self) -> Result<Box<T>>

Queries the data of this DataAccessor<'_, T> as a box

This produces a Box<T>. In order to produce an owned T on the stack (requiring T: Sized), use the get method.

This returns the data of the accessor without a change stamp. In order to query both the data and the change stamp, use the query_boxed method.

The data returned by this method are the data of the underlying state for the update that caused the listener call to which this DataAccessor<'_, T> was passed. Note that in contrast to OwnedState::get_boxed or BorrowedState::get_boxed, this does not involve an OS call.

§Errors

Returns an error if the queried data is not a valid T

source

pub fn query_boxed(self) -> Result<StampedData<Box<T>>>

Queries the data of this DataAccessor<'_, T> as a box together with their change stamp

This produces a Box<T>. In order to produce an owned T on the stack (requiring T: Sized), use the query method.

This returns the data of the accessor together with their change stamp as a StampedData<Box<T>>. In order to only query the data, use the get_boxed method.

The data returned by this method are the data of the underlying state for the update that caused the listener call to which this DataAccessor<'_, T> was passed. Note that in contrast to OwnedState::query_boxed or BorrowedState::query_boxed, this does not involve an OS call.

§Errors

Returns an error if the queried data is not a valid T

Trait Implementations§

source§

impl<T> Clone for DataAccessor<'_, T>
where T: ?Sized,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for DataAccessor<'_, T>
where T: ?Sized,

source§

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

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

impl<T> Copy for DataAccessor<'_, T>
where T: ?Sized,

Auto Trait Implementations§

§

impl<'a, T> Freeze for DataAccessor<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for DataAccessor<'a, T>
where T: ?Sized,

§

impl<'a, T> Send for DataAccessor<'a, T>
where T: ?Sized,

§

impl<'a, T> Sync for DataAccessor<'a, T>
where T: ?Sized,

§

impl<'a, T> Unpin for DataAccessor<'a, T>
where T: ?Sized,

§

impl<'a, T> UnwindSafe for DataAccessor<'a, T>
where T: ?Sized,

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more