Skip to main content

PokeOption

Struct PokeOption 

Source
pub struct PokeOption<'mem, 'facet> { /* private fields */ }
Expand description

Lets you mutate an option (implements mutable option operations)

Implementations§

Source§

impl<'mem, 'facet> PokeOption<'mem, 'facet>

Source

pub const unsafe fn new(value: Poke<'mem, 'facet>, def: OptionDef) -> Self

Creates a new poke option

§Safety

The caller must ensure that def contains valid vtable function pointers that correctly implement the option operations for the actual type, and that the inner type matches def.t().

Source

pub const fn def(&self) -> OptionDef

Returns the option definition

Source

pub const fn vtable(&self) -> &'static OptionVTable

Returns the option vtable

Source

pub fn is_some(&self) -> bool

Returns whether the option is Some

Source

pub fn is_none(&self) -> bool

Returns whether the option is None

Source

pub fn value(&self) -> Option<Peek<'_, 'facet>>

Returns the inner value as a read-only Peek if the option is Some, None otherwise.

Source

pub fn value_mut(&mut self) -> Option<Poke<'_, 'facet>>

Returns the inner value as a mutable Poke if the option is Some, None otherwise.

Source

pub fn set_some<T: Facet<'facet>>( &mut self, value: T, ) -> Result<(), ReflectError>

Sets the option to Some(value), dropping the previous value.

Source

pub fn set_some_from_heap<const BORROW: bool>( &mut self, value: HeapValue<'facet, BORROW>, ) -> Result<(), ReflectError>

Type-erased set_some.

Accepts a HeapValue whose shape must match the option’s inner type. The value is moved out of the HeapValue into the option; the HeapValue’s backing memory is freed without running drop (the vtable has already consumed the value via ptr::read).

Use this when you hold a reflection-built value and can’t produce a concrete T.

Source

pub fn set_none(&mut self)

Sets the option to None, dropping the previous value.

Source

pub const fn into_inner(self) -> Poke<'mem, 'facet>

Converts this PokeOption back into a Poke

Source

pub fn as_peek_option(&self) -> PeekOption<'_, 'facet>

Returns a read-only PeekOption view

Trait Implementations§

Source§

impl<'mem, 'facet> Debug for PokeOption<'mem, 'facet>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'mem, 'facet> Freeze for PokeOption<'mem, 'facet>

§

impl<'mem, 'facet> RefUnwindSafe for PokeOption<'mem, 'facet>

§

impl<'mem, 'facet> !Send for PokeOption<'mem, 'facet>

§

impl<'mem, 'facet> !Sync for PokeOption<'mem, 'facet>

§

impl<'mem, 'facet> Unpin for PokeOption<'mem, 'facet>

§

impl<'mem, 'facet> UnsafeUnpin for PokeOption<'mem, 'facet>

§

impl<'mem, 'facet> !UnwindSafe for PokeOption<'mem, 'facet>

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.