Skip to main content

PrimitiveOption

Struct PrimitiveOption 

Source
#[repr(C)]
pub struct PrimitiveOption<T: Copy> { pub has_value: u8, pub _pad: [u8; 7], pub value: T, }
Expand description

Option for primitive (non-pointer) types.

§Memory layout (16 bytes for T=f64/i64, 8 bytes could suffice for smaller T)

Offset  Size  Field
------  ----  -----
  0       1   has_value (0 = None, 1 = Some)
  1       7   _pad (align to 8)
  8    sz(T)  value

Fields§

§has_value: u8

0 = None, 1 = Some.

§_pad: [u8; 7]

Padding to align value to 8 bytes.

§value: T

The value (only valid when has_value == 1).

Implementations§

Source§

impl<T: Copy> PrimitiveOption<T>

Source

pub fn some(value: T) -> Self

Create a Some variant.

Source

pub fn none() -> Self
where T: Default,

Create a None variant.

§Safety

The value field is left zeroed and must not be read.

Source

pub fn is_some(&self) -> bool

Whether this is Some.

Source

pub fn is_none(&self) -> bool

Whether this is None.

Source

pub fn get(&self) -> Option<T>

Get the value, if present.

Auto Trait Implementations§

§

impl<T> Freeze for PrimitiveOption<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PrimitiveOption<T>
where T: RefUnwindSafe,

§

impl<T> Send for PrimitiveOption<T>
where T: Send,

§

impl<T> Sync for PrimitiveOption<T>
where T: Sync,

§

impl<T> Unpin for PrimitiveOption<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for PrimitiveOption<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for PrimitiveOption<T>
where T: 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> 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.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,