Skip to main content

Access

Trait Access 

Source
pub trait Access<T>: InferPresence<T> {
    type RemainderFrom<Source: Access<T>>: Access<T>;

    const IS_ABSENT: bool;

    // Required methods
    fn get(&self) -> Option<&T>;
    fn get_mut(&mut self) -> Option<&mut T>;
    fn into_option(self) -> Option<T>;
    fn from_value(value: T) -> (Self, Self::RemainderFrom<T>)
       where Self: Sized;
    fn try_from_option(
        value: Option<T>,
    ) -> Result<(Self, Self::RemainderFrom<Option<T>>), Option<T>>
       where Self: Sized;
}
Expand description

Uniform field access for Present, Optional, or Absent.

Required Associated Constants§

Source

const IS_ABSENT: bool

Compile-time constant indicating if this field is absent.

Required Associated Types§

Source

type RemainderFrom<Source: Access<T>>: Access<T>

Remainder type when extracting Self from Source.

Required Methods§

Source

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

Get field reference if present.

Source

fn get_mut(&mut self) -> Option<&mut T>

Get mutable field reference if present.

Source

fn into_option(self) -> Option<T>

Consume and convert to Option.

Source

fn from_value(value: T) -> (Self, Self::RemainderFrom<T>)
where Self: Sized,

Construct from a value.

Source

fn try_from_option( value: Option<T>, ) -> Result<(Self, Self::RemainderFrom<Option<T>>), Option<T>>
where Self: Sized,

Try to construct from an option.

§Errors

Returns Err with the original Option<T> if the conversion cannot be performed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> Access<T> for Option<T>

Source§

const IS_ABSENT: bool = false

Source§

type RemainderFrom<Source: Access<T>> = PhantomData<T>

Source§

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

Source§

fn get_mut(&mut self) -> Option<&mut T>

Source§

fn into_option(self) -> Option<T>

Source§

fn from_value(value: T) -> (Self, Self::RemainderFrom<T>)

Source§

fn try_from_option( value: Option<T>, ) -> Result<(Self, Self::RemainderFrom<Option<T>>), Option<T>>

Source§

impl<T> Access<T> for PhantomData<T>

Source§

const IS_ABSENT: bool = true

Source§

type RemainderFrom<Source: Access<T>> = Source

Source§

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

Source§

fn get_mut(&mut self) -> Option<&mut T>

Source§

fn into_option(self) -> Option<T>

Source§

fn from_value(value: T) -> (Self, Self::RemainderFrom<T>)

Source§

fn try_from_option( value: Option<T>, ) -> Result<(Self, Self::RemainderFrom<Option<T>>), Option<T>>

Implementors§

Source§

impl<T: Sized> Access<T> for T

Source§

const IS_ABSENT: bool = false

Source§

type RemainderFrom<Source: Access<T>> = PhantomData<T>