pub struct OptZero<T>(/* private fields */)
where
T: NotZeroable;Expand description
Represents an Option where a zero value is considered None.
Wraps an FFI type that SHOULD be non zeroable, and provides a safe way to handle zero values as None
The reason why i used “SHOULD” is because that type may be zeroed if passed from a foreign callsite so extra handling is required, this type makes it safe for it to be zeroed.
Implementations§
Source§impl<T> OptZero<T>where
T: NotZeroable,
impl<T> OptZero<T>where
T: NotZeroable,
Sourcepub const fn some(x: T) -> OptZero<T>
pub const fn some(x: T) -> OptZero<T>
Creates a new OptZero that represents a Some value from a value.
Sourcepub fn from_option(opt: Option<T>) -> OptZero<T>
pub fn from_option(opt: Option<T>) -> OptZero<T>
Creates a new OptZero from an Option.
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Converts this OptZero into an Option.
Sourcepub fn as_option(&self) -> Option<&T>
pub fn as_option(&self) -> Option<&T>
Returns a reference to the contained value or None if the value is zeroed.
Sourcepub unsafe fn into_inner_unchecked(self) -> T
pub unsafe fn into_inner_unchecked(self) -> T
Returns the inner value whether or not it is zeroed.
§Safety
unsafe because OptZero works with the promise that it is going to handle zeroed values.
Sourcepub fn map<F, U>(self, f: F) -> OptZero<U>where
F: FnOnce(T) -> U,
U: NotZeroable,
pub fn map<F, U>(self, f: F) -> OptZero<U>where
F: FnOnce(T) -> U,
U: NotZeroable,
Maps a OptZero to another OptZero using a function.
Trait Implementations§
impl<T> Copy for OptZero<T>where
T: Copy + NotZeroable,
impl<T> Eq for OptZero<T>where
T: NotZeroable + Eq,
Auto Trait Implementations§
impl<T> Freeze for OptZero<T>where
T: Freeze,
impl<T> RefUnwindSafe for OptZero<T>where
T: RefUnwindSafe,
impl<T> Send for OptZero<T>where
T: Send,
impl<T> Sync for OptZero<T>where
T: Sync,
impl<T> Unpin for OptZero<T>where
T: Unpin,
impl<T> UnwindSafe for OptZero<T>where
T: UnwindSafe,
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