Skip to main content

COption

Enum COption 

Source
#[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§

§

None = 0

§

Some(TValue)

Implementations§

Source§

impl<TValue> COption<TValue>
where TValue: ReprC,

Source

pub const fn is_some(&self) -> bool

Returns true if the enum holds COption::Some, false otherwise.

Source

pub const fn is_none(&self) -> bool

Returns true if the enum holds COption::None, false otherwise.

Source

pub fn expect(self, message: &str) -> TValue

Unwraps currently stored COption::Some value.

§Panics

Only when self actually holds a COption::None value.

Source

pub const fn unwrap(self) -> TValue

Unwraps currently stored COption::Some value.

§Panics

Only when self actually holds a COption::None value.

Source

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.

Source

pub const fn into_option(self) -> Option<TValue>

Converts COption into standard Option.

Source

pub const fn from_option(option: Option<TValue>) -> Self

Converts standard Option into COption.

Source

pub const fn as_ref(&self) -> COption<&TValue>

Converts COption into a reference to the stored value.

Source

pub const fn as_mut(&mut self) -> COption<&mut TValue>

Converts COption into a mutable reference to the stored value.

Trait Implementations§

Source§

impl<TValue: ReprC + Clone> Clone for COption<TValue>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<TValue> Debug for COption<TValue>
where TValue: ReprC + Debug,

Source§

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

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

impl<TValue: ReprC> Default for COption<TValue>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, TValue: ReprC + Deserialize<'de>> Deserialize<'de> for COption<TValue>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<TValue: ReprC + Display> Display for COption<TValue>

Source§

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

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

impl<TValue: ReprC + Eq> Eq for COption<TValue>

Source§

impl<TValue: ReprC> From<COption<TValue>> for Option<TValue>

Source§

fn from(option: COption<TValue>) -> Self

Converts to this type from the input type.
Source§

impl<TValue: ReprC> From<Option<TValue>> for COption<TValue>

Source§

fn from(option: Option<TValue>) -> Self

Converts to this type from the input type.
Source§

impl<TValue: ReprC + Hash> Hash for COption<TValue>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<TValue: ReprC + PartialEq> PartialEq for COption<TValue>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<TValue> ReprC for COption<TValue>
where TValue: ReprC,

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<TValue: ReprC + Serialize> Serialize for COption<TValue>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<TValue: ReprC + TryClone> TryClone for COption<TValue>

Source§

type Error = <TValue as TryClone>::Error

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Tries to clone the type. Read more

Auto Trait Implementations§

§

impl<TValue> Freeze for COption<TValue>
where TValue: Freeze,

§

impl<TValue> RefUnwindSafe for COption<TValue>
where TValue: RefUnwindSafe,

§

impl<TValue> Send for COption<TValue>
where TValue: Send,

§

impl<TValue> Sync for COption<TValue>
where TValue: Sync,

§

impl<TValue> Unpin for COption<TValue>
where TValue: Unpin,

§

impl<TValue> UnsafeUnpin for COption<TValue>
where TValue: UnsafeUnpin,

§

impl<TValue> UnwindSafe for COption<TValue>
where TValue: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.