Struct wnf::DataAccessor
source · pub struct DataAccessor<'a, T>where
T: ?Sized,{ /* private fields */ }
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,
impl<'a, T> DataAccessor<'a, T>where
T: ?Sized,
sourcepub const fn cast<U>(self) -> DataAccessor<'a, U>where
U: ?Sized,
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
.
sourcepub const fn change_stamp(self) -> ChangeStamp
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>,
impl<T> DataAccessor<'_, T>where
T: Read<T>,
sourcepub fn get(self) -> Result<T>
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
sourcepub fn query(self) -> Result<StampedData<T>>
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>
impl<T> DataAccessor<'_, T>
sourcepub fn get_boxed(self) -> Result<Box<T>>
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
sourcepub fn query_boxed(self) -> Result<StampedData<Box<T>>>
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