[−][src]Trait smart_access::Cps
Anything that can provide (or refuse to provide) a mutable parameter for a function.
You do not need to implement Cps
for anything: it's already implemented
for AT
and &mut T
, and it's sufficient for almost all
purposes. Implement At
instead.
The main usecase for this trait is to be used as a bound on
parameter and return types of functions:
Cps<View=T>
-bounded type can be thought of as a
lifetimeless analogue of &mut T
.
In fact all default implementors of Cps
have an internal lifetime
parameter. If needed it can be exposed using + 'a
syntax in a trait
bound, but in many cases one can do very well without any explicit lifetimes.
Associated Types
Loading content...Required methods
fn access<R, F>(self, f: F) -> Option<R> where
Self: Sized,
F: FnOnce(&mut Self::View) -> R,
Self: Sized,
F: FnOnce(&mut Self::View) -> R,
Returns Some(f(..))
or None
.
The rules governing the value returned are defined by an implementation.
Provided methods
fn replace(self, new_val: Self::View) -> Option<Self::View> where
Self: Sized,
Self::View: Sized,
Self: Sized,
Self::View: Sized,
Equivalent to self.access(|x| std::mem::replace(x, new_val))
fn touch(self) -> Option<()> where
Self: Sized,
Self: Sized,
Equivalent to self.access(|_| ())
fn at<Index>(self, i: Index) -> AT<AttachedRoot<Self>, Index> where
Self: Sized,
Self::View: At<Index>,
Self: Sized,
Self::View: At<Index>,
“Moves in the direction” of the provided index.
Not intended for overriding.
If you see scary AttachedRoot<Self>
as a part of the return type
then you have enabled the detach
feature. Without detach
that part
is simply Self
.
fn batch_ct(self) -> CpsBatch<Self, ()> where
Self: Sized,
Self: Sized,
fn batch_rt<R>(
self
) -> CpsBatch<Self, Vec<Box<dyn FnOnce(&mut Self::View, Option<R>) -> R>>> where
Self: Sized,
self
) -> CpsBatch<Self, Vec<Box<dyn FnOnce(&mut Self::View, Option<R>) -> R>>> where
Self: Sized,
fn attach<Path>(self, path: Path) -> Path::Output where
Self: Sized,
Path: Attach<Self>,
Self: Sized,
Path: Attach<Self>,
Implementations on Foreign Types
impl<'_, T: ?Sized> Cps for &'_ mut T
[src]
access
is guaranteed to return Some(f(..))
Implementors
impl<T, V: ?Sized, Index> Cps for AT<T, Index> where
T: Cps<View = V>,
V: At<Index>,
[src]
T: Cps<View = V>,
V: At<Index>,
access
returns Some
/ None
according to rules described here