[][src]Trait smart_access::At

pub trait At<Index> {
    type View: ?Sized;
    fn access_at<R, F>(&mut self, i: Index, f: F) -> Option<R>
    where
        F: FnOnce(&mut Self::View) -> R
; }

A smart access protocol.

It is intended to be used through a Cps-bounded type.

Associated Types

type View: ?Sized

Loading content...

Required methods

fn access_at<R, F>(&mut self, i: Index, f: F) -> Option<R> where
    F: FnOnce(&mut Self::View) -> R, 

Accesses data at a specified index.

If there is some data (or some bidirectional procedure) associated with the index then access_at must apply f to this data.

If the transformation result can be placed back into self then it must be placed back and access_at must return Some(f(data)).

Otherwise None must be returned and self must stay unchanged.

In essence access_at returns None if and only if self has not been touched.

Note

The following two cases are indistinguishable:

  • a view couldn't be obtained (and thus f had not been called)
  • f had been called but failed to mutate the view in a meaningful way

If you need to distinguish between these cases you can use some side-effect of f.

Loading content...

Implementations on Foreign Types

impl<T> At<usize> for [T][src]

type View = T

impl<T> At<Range<usize>> for [T][src]

type View = [T]

impl<T> At<RangeFrom<usize>> for [T][src]

type View = [T]

impl<T> At<RangeFull> for [T][src]

type View = [T]

impl<T> At<RangeInclusive<usize>> for [T][src]

type View = [T]

impl<T> At<RangeTo<usize>> for [T][src]

type View = [T]

impl<T> At<RangeToInclusive<usize>> for [T][src]

type View = [T]

impl<T> At<()> for Option<T>[src]

type View = T

impl<T, S> At<()> for Result<T, S>[src]

type View = T

impl<T> At<usize> for Vec<T>[src]

type View = T

impl<T> At<Range<usize>> for Vec<T>[src]

type View = Vec<T>

impl<T> At<RangeFrom<usize>> for Vec<T>[src]

type View = Vec<T>

impl<T> At<RangeFull> for Vec<T>[src]

type View = Vec<T>

impl<T> At<RangeInclusive<usize>> for Vec<T>[src]

type View = Vec<T>

impl<T> At<RangeTo<usize>> for Vec<T>[src]

type View = Vec<T>

impl<T> At<RangeToInclusive<usize>> for Vec<T>[src]

type View = Vec<T>

impl<'_, Q: ?Sized, K, V> At<&'_ Q> for HashMap<K, V> where
    K: Borrow<Q> + Eq + Hash,
    Q: Eq + Hash
[src]

type View = V

impl<K, V> At<(K, V)> for HashMap<K, V> where
    K: Eq + Hash
[src]

type View = V

impl<'_, Q: ?Sized, K, V> At<&'_ Q> for BTreeMap<K, V> where
    K: Borrow<Q> + Ord,
    Q: Ord
[src]

type View = V

impl<K, V> At<(K, V)> for BTreeMap<K, V> where
    K: Ord
[src]

type View = V

Loading content...

Implementors

Loading content...