Mapped

Struct Mapped 

Source
pub struct Mapped<T, U>
where T: Guarded, U: ?Sized,
{ /* private fields */ }
Expand description

A mapped guard, which contains a guarded owned pointer, and an immutable reference to that pointer. It has had a one-time closure applied to it, but only the output of the closure is stored, not the closure itself. This is similar to how crates like owning_ref work.

Implementations§

Source§

impl<T, U> Mapped<T, U>
where T: Guarded, U: ?Sized,

Source

pub fn into_original(self) -> T

Move the inner guarded pointer out from the Mapped wrapper, cancelling the temporary borrow.

Source

pub fn original_by_ref(&self) -> &T

Get the original pointer, by immutable reference.

Source

pub fn get_ref(&self) -> &U

Retrieve an immutable reference to the mapped data.

Source

pub fn and_then<F, V>(self, f: F) -> Mapped<T, V>
where F: FnOnce(&U) -> &V, V: ?Sized,

Map the mapped wrapper again, converting &U to &V.

Source

pub fn try_and_then<F, V, E>(self, f: F) -> Result<Mapped<T, V>, E>
where F: FnOnce(&U) -> Result<&V, E>, V: ?Sized,

Attempt to map the reference again, but with the ability to short-circuit on errors.

Trait Implementations§

Source§

impl<T, U> Debug for Mapped<T, U>
where T: Guarded, U: ?Sized + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, U> Guarded for Mapped<T, U>
where T: Guarded, U: ?Sized,

Source§

type Target = U

The target pointee that this pointer may dereference into. There are no real restrictions to what this type can be. However, the user must not assume that simply because a &Target reference is protected, that references indirectly derived (via Deref and other traits) would also be protected.
Source§

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

Borrow the pointee, into a fixed reference that can be sent directly and safely to e.g. memory-sharing completion-based I/O interfaces. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for Mapped<T, U>
where T: Freeze, U: ?Sized,

§

impl<T, U> RefUnwindSafe for Mapped<T, U>

§

impl<T, U> !Send for Mapped<T, U>

§

impl<T, U> !Sync for Mapped<T, U>

§

impl<T, U> Unpin for Mapped<T, U>
where T: Unpin, U: ?Sized,

§

impl<T, U> UnwindSafe for Mapped<T, U>
where T: UnwindSafe, U: RefUnwindSafe + ?Sized,

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> GuardedExt for T
where T: Guarded,

Source§

fn map<F, T>(this: Self, f: F) -> Mapped<Self, T>
where F: FnOnce(&<Self as Guarded>::Target) -> &T, T: ?Sized,

Apply a function to the pointee, creating a new guarded type that dereferences into the result of that function. Read more
Source§

fn try_map<F, T, E>(this: Self, f: F) -> Result<Mapped<Self, T>, E>
where F: FnOnce(&<Self as Guarded>::Target) -> Result<&T, E>, T: ?Sized,

Apply a fallible function to the pointee, creating a new guarded type that dereferences into the result of that function. Read more
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.