Struct dereffer::DerefsTo

source ·
pub struct DerefsTo<Inner, Ref: ?Sized> { /* private fields */ }
Expand description

A struct that holds an inner value and a function that is used deref the Inner value into a &Ref.

As with Deref, the dereffer function must not fail. It typically just accesses an arbitrary field reachable from Inner.

This is also useful to prevent a caller from accessing all of Inner, rather only giving them access to Ref.

Implementations§

source§

impl<Inner, Ref: ?Sized> DerefsTo<Inner, Ref>

source

pub const fn new(inner: Inner, deref_func: fn(_: &Inner) -> &Ref) -> Self

source§

impl<Inner, Ref> DerefsTo<Inner, Ref>where Inner: Deref<Target = Ref>, Ref: ?Sized,

source

pub const fn new_default(inner: Inner) -> Self

Creates a new wrapper with the default, simple deref function, Deref::deref().

Trait Implementations§

source§

impl<Inner, Ref: ?Sized> Deref for DerefsTo<Inner, Ref>

§

type Target = Ref

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<Inner, Ref: ?Sized> RefUnwindSafe for DerefsTo<Inner, Ref>where Inner: RefUnwindSafe,

§

impl<Inner, Ref: ?Sized> Send for DerefsTo<Inner, Ref>where Inner: Send,

§

impl<Inner, Ref: ?Sized> Sync for DerefsTo<Inner, Ref>where Inner: Sync,

§

impl<Inner, Ref: ?Sized> Unpin for DerefsTo<Inner, Ref>where Inner: Unpin,

§

impl<Inner, Ref: ?Sized> UnwindSafe for DerefsTo<Inner, Ref>where Inner: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.