Struct wnf::OpaqueData
source · pub struct OpaqueData { /* private fields */ }
Expand description
A placeholder for state data whose content is irrelevant
This type can be “read” from any state regardless of the size of the state data. It doesn’t contain the actual data
but just their size, which can be obtained via the OpaqueData::size
method. This is useful on different
occasions, for instance:
- If you want to query the size of state data without querying the actual data:
let state = OwnedState::<u32>::create_temporary()?;
state.set(&42)?;
assert_eq!(state.as_state().cast::<OpaqueData>().get()?.size(), 4);
// Less efficient alternative:
assert_eq!(state.as_state().cast::<[u8]>().get_boxed()?.len(), 4);
- If you want to check if a state can be read without querying its actual data:
// Here we could have used any type `T: NoUninit` in place of `u32`
let state = OwnedState::<u32>::create_temporary()?;
state.set(&42)?;
let can_read = state.cast::<OpaqueData>().get().is_ok();
assert!(can_read);
Another use case is reading the change stamp of a state without knowing what the actual data look like, but that is
already implemented in OwnedState::change_stamp
.
Implementations§
source§impl OpaqueData
impl OpaqueData
sourcepub const fn size(self) -> usize
pub const fn size(self) -> usize
Returns the size in bytes of this OpaqueData
Trait Implementations§
source§impl Clone for OpaqueData
impl Clone for OpaqueData
source§fn clone(&self) -> OpaqueData
fn clone(&self) -> OpaqueData
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for OpaqueData
impl Debug for OpaqueData
source§impl Hash for OpaqueData
impl Hash for OpaqueData
source§impl Ord for OpaqueData
impl Ord for OpaqueData
source§fn cmp(&self, other: &OpaqueData) -> Ordering
fn cmp(&self, other: &OpaqueData) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for OpaqueData
impl PartialEq for OpaqueData
source§fn eq(&self, other: &OpaqueData) -> bool
fn eq(&self, other: &OpaqueData) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for OpaqueData
impl PartialOrd for OpaqueData
source§fn partial_cmp(&self, other: &OpaqueData) -> Option<Ordering>
fn partial_cmp(&self, other: &OpaqueData) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for OpaqueData
impl Eq for OpaqueData
impl Read<OpaqueData> for OpaqueData
impl StructuralPartialEq for OpaqueData
Auto Trait Implementations§
impl Freeze for OpaqueData
impl RefUnwindSafe for OpaqueData
impl Send for OpaqueData
impl Sync for OpaqueData
impl Unpin for OpaqueData
impl UnwindSafe for OpaqueData
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more