#[repr(u8)]pub enum COption<TValue>where
TValue: ReprC,{
None = 0,
Some(TValue),
}Expand description
This enum is essentially the same as the standard Option,
except it is #[repr(C)] and thus safe to use a across the
ffi boundaries.
It additionally provides const variants of Option methods.
Variants§
Implementations§
Source§impl<TValue> COption<TValue>where
TValue: ReprC,
impl<TValue> COption<TValue>where
TValue: ReprC,
Sourcepub const fn is_some(&self) -> bool
pub const fn is_some(&self) -> bool
Returns true if the enum holds COption::Some,
false otherwise.
Sourcepub const fn is_none(&self) -> bool
pub const fn is_none(&self) -> bool
Returns true if the enum holds COption::None,
false otherwise.
Sourcepub fn expect(self, message: &str) -> TValue
pub fn expect(self, message: &str) -> TValue
Unwraps currently stored COption::Some value.
§Panics
Only when self actually holds a COption::None value.
Sourcepub const fn unwrap(self) -> TValue
pub const fn unwrap(self) -> TValue
Unwraps currently stored COption::Some value.
§Panics
Only when self actually holds a COption::None value.
Sourcepub const unsafe fn unwrap_unchecked(self) -> TValue
pub const unsafe fn unwrap_unchecked(self) -> TValue
Unwraps currently stored COption::Some value.
§Safety
This function does not verify whether the stored value
is actually COption::Some. The behaviour is undefined if it is not.
Sourcepub const fn into_option(self) -> Option<TValue>
pub const fn into_option(self) -> Option<TValue>
Converts COption into standard Option.
Sourcepub const fn from_option(option: Option<TValue>) -> Self
pub const fn from_option(option: Option<TValue>) -> Self
Converts standard Option into COption.
Sourcepub const fn as_ref(&self) -> COption<&TValue>
pub const fn as_ref(&self) -> COption<&TValue>
Converts COption into a reference to the stored value.
Sourcepub const fn as_mut(&mut self) -> COption<&mut TValue>
pub const fn as_mut(&mut self) -> COption<&mut TValue>
Converts COption into a mutable reference to the stored value.