GuardedExt

Trait GuardedExt 

Source
pub trait GuardedExt:
    Sealed
    + Guarded
    + Sized {
    // Provided methods
    fn map<F, T>(this: Self, f: F) -> Mapped<Self, T>
       where F: FnOnce(&<Self as Guarded>::Target) -> &T,
             T: ?Sized { ... }
    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 { ... }
}
Expand description

An extension trait for convenience methods, that is automatically implemented for all Guarded types.

Provided Methods§

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.

The closure is only evaluated once, and the resulting wrapper will only store one null-optimizable additional word, for the reference.

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.

If the function fails, the error is returned directly, and no further mapping is made.

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§

Source§

impl<T> GuardedExt for T
where T: Guarded + Sized,