Wrapper

Trait Wrapper 

Source
pub trait Wrapper: RawWrapper {
    // Required methods
    fn new(value: Self::Item) -> Self;
    fn value(self) -> Self::Item;
    fn get(&self) -> &Self::Item;
    fn get_mut(&mut self) -> &mut Self::Item;

    // Provided methods
    fn replace(&mut self, value: Self::Item) -> Self::Item { ... }
    fn set(&mut self, value: Self::Item) -> &mut Self { ... }
    fn swap(&mut self, other: &mut Self) { ... }
    fn take(&mut self) -> Self::Item
       where Self::Item: Default { ... }
}
Expand description

The Wrapper trait is used to establish a common interface for all simplemented structures that “wrap” a single value. Essentially, any type capable of implementing #[repr(transparent)] can be considered a wrapper.

Required Methods§

Source

fn new(value: Self::Item) -> Self

returns a new instance of the wrapper initialized with the given value

Source

fn value(self) -> Self::Item

consumes the wrapper to return the stored value

Source

fn get(&self) -> &Self::Item

returns an immutable reference to the stored value

Source

fn get_mut(&mut self) -> &mut Self::Item

returns a mutable reference to the stored value

Provided Methods§

Source

fn replace(&mut self, value: Self::Item) -> Self::Item

replace replaces the value inside the wrapper with a new one, returning the old value.

Source

fn set(&mut self, value: Self::Item) -> &mut Self

set the value and return a mutable reference to the wrapper

Source

fn swap(&mut self, other: &mut Self)

swap swaps the inner values of two instances.

Source

fn take(&mut self) -> Self::Item
where Self::Item: Default,

take takes the value out of the wrapper, leaving it in the logical default in its place

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§