[][src]Trait smart_access::Cps

pub trait Cps {
    type View: ?Sized;
    fn access<R, F>(self, f: F) -> Option<R>
    where
        Self: Sized,
        F: FnOnce(&mut Self::View) -> R
; fn replace(self, new_val: Self::View) -> Option<Self::View>
    where
        Self: Sized,
        Self::View: Sized
, { ... }
fn touch(self) -> Option<()>
    where
        Self: Sized
, { ... }
fn at<Index>(self, i: Index) -> AT<Self, Index>
    where
        Self: Sized,
        Self::View: At<Index>
, { ... }
fn batch_ct(self) -> CpsBatch<Self, ()>
    where
        Self: Sized
, { ... }
fn batch_rt<R>(
        self
    ) -> CpsBatch<Self, Vec<Box<dyn FnOnce(&mut Self::View, Option<R>) -> R>>>
    where
        Self: Sized
, { ... } }

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

type View: ?Sized

Loading content...

Required methods

fn access<R, F>(self, f: F) -> Option<R> where
    Self: Sized,
    F: FnOnce(&mut Self::View) -> R, 

Returns Some(f(..)) or None.

The rules governing the value returned are defined by an implementation.

Loading content...

Provided methods

fn replace(self, new_val: Self::View) -> Option<Self::View> where
    Self: Sized,
    Self::View: Sized

Equivalent to self.access(|x| std::mem::replace(x, new_val))

fn touch(self) -> Option<()> where
    Self: Sized

Equivalent to self.access(|_| ())

fn at<Index>(self, i: Index) -> AT<Self, Index> where
    Self: Sized,
    Self::View: At<Index>, 

“Moves in the direction” of the provided index.

It seems to be impossible to override at in a meaningful way.

fn batch_ct(self) -> CpsBatch<Self, ()> where
    Self: Sized

Constructs a compile-time batch.

fn batch_rt<R>(
    self
) -> CpsBatch<Self, Vec<Box<dyn FnOnce(&mut Self::View, Option<R>) -> R>>> where
    Self: Sized

Constructs a runtime batch.

Loading content...

Implementations on Foreign Types

impl<'_, T: ?Sized> Cps for &'_ mut T[src]

access is guaranteed to return Some(f(..))

type View = T

Loading content...

Implementors

impl<T, V: ?Sized, Index> Cps for AT<T, Index> where
    T: Cps<View = V>,
    V: At<Index>, 
[src]

access returns Some / None according to rules described here

type View = V::View

Loading content...