[−][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
F: FnOnce(&mut Self::View) -> R,
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::View: Sized,
Self::View: Sized,
Equivalent to self.access(|x| std::mem::replace(x, new_val))
fn touch(self) -> Option<()>
Equivalent to self.access(|_| ())
fn get_clone(self) -> Option<Self::View> where
Self::View: Sized + Clone,
Self::View: Sized + Clone,
Equivalent to self.access(|x| x.clone())
fn at<Index>(self, i: Index) -> AT<Self, ((), Index)> where
Self::View: At<Index>,
Self::View: At<Index>,
“Moves in the direction” of the provided index.
Not intended for overriding.
fn batch_ct(self) -> CpsBatch<Self, ()>
fn batch_rt<R>(
self
) -> CpsBatch<Self, Vec<Box<dyn FnOnce(&mut Self::View, Option<R>) -> R>>>
self
) -> CpsBatch<Self, Vec<Box<dyn FnOnce(&mut Self::View, Option<R>) -> R>>>
fn attach<Path, V: ?Sized>(self, path: Path) -> AT<Self, Path::List> where
Path: Attach<Self::View, View = V>,
Path: Attach<Self::View, View = V>,
fn cut(self) -> AT<Self, ()>
Creates a new detach point.
Not intended for overriding.
Present only on detach
.
Usage example
The .detach()
method
detaches a part beginning at the closest detach point:
let mut foo = Some(Some(1)); let mut bar = Some(2); // the detached part // /------\ let (left, right) = foo.at(()).cut().at(()).detach(); assert!(bar.attach(right).replace(3) == Some(2)); assert!(bar == Some(3)); assert!(left.at(()).replace(4) == Some(1)); assert!(foo == Some(Some(4)));
Implementors
impl<'_, T: ?Sized> Cps for &'_ mut T
[src]
access
is guaranteed to return Some(f(..))
impl<CPS: Cps, Path> Cps for AT<CPS, Path> where
Path: AtView<CPS::View>,
[src]
Path: AtView<CPS::View>,
access
returns Some
/ None
according to the rules described here