Skip to main content

At

Trait At 

Source
pub trait At<Index> {
    type View: ?Sized;

    // Required method
    fn access_at<R, F>(&mut self, i: Index, f: F) -> Option<R>
       where F: FnOnce(&mut Self::View) -> R;
}
Expand description

A smart access protocol.

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

Required Associated Types§

Required Methods§

Source

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<K, V, M> At<(K, V, M)> for BTreeMap<K, V>
where K: Ord, M: FnOnce(&mut V),

Source§

type View = V

Source§

fn access_at<R, F>(&mut self, kvm: (K, V, M), f: F) -> Option<R>
where F: FnOnce(&mut V) -> R,

Source§

impl<K, V, M> At<(K, V, M)> for HashMap<K, V>
where K: Eq + Hash, M: FnOnce(&mut V),

Available on crate feature hashbrown only.
Source§

type View = V

Source§

fn access_at<R, F>(&mut self, kvm: (K, V, M), f: F) -> Option<R>
where F: FnOnce(&mut V) -> R,

Source§

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

Source§

type View = V

Source§

fn access_at<R, F>(&mut self, kv: (K, V), f: F) -> Option<R>
where F: FnOnce(&mut V) -> R,

Source§

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

Available on crate feature hashbrown only.
Source§

type View = V

Source§

fn access_at<R, F>(&mut self, kv: (K, V), f: F) -> Option<R>
where F: FnOnce(&mut V) -> R,

Source§

impl<Q, K, V> At<&Q> for BTreeMap<K, V>
where K: Borrow<Q> + Ord, Q: ?Sized + Ord,

Source§

type View = V

Source§

fn access_at<R, F>(&mut self, i: &Q, f: F) -> Option<R>
where F: FnOnce(&mut V) -> R,

Source§

impl<Q, K, V> At<&Q> for HashMap<K, V>
where K: Borrow<Q> + Eq + Hash, Q: ?Sized + Eq + Hash,

Available on crate feature hashbrown only.
Source§

type View = V

Source§

fn access_at<R, F>(&mut self, i: &Q, f: F) -> Option<R>
where F: FnOnce(&mut V) -> R,

Source§

impl<Q, T> At<&Q> for BTreeSet<T>
where T: Borrow<Q> + Ord, Q: ?Sized + Ord,

Source§

type View = T

Source§

fn access_at<R, F>(&mut self, i: &Q, f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Source§

impl<Q, T> At<&Q> for HashSet<T>
where T: Borrow<Q> + Eq + Hash, Q: ?Sized + Eq + Hash,

Available on crate feature hashbrown only.
Source§

type View = T

Source§

fn access_at<R, F>(&mut self, i: &Q, f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Source§

impl<T, S> At<()> for Result<T, S>

Source§

type View = T

Source§

fn access_at<R, F>(&mut self, _: (), f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Source§

impl<T> At<()> for Option<T>

Source§

type View = T

Source§

fn access_at<R, F>(&mut self, _: (), f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Source§

impl<T> At<()> for Vec<T>

Source§

type View = [T]

Source§

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

Source§

impl<T> At<(T, ())> for BTreeSet<T>
where T: Ord,

Source§

type View = T

Source§

fn access_at<R, F>(&mut self, item: (T, ()), f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Source§

impl<T> At<(T, ())> for HashSet<T>
where T: Eq + Hash,

Available on crate feature hashbrown only.
Source§

type View = T

Source§

fn access_at<R, F>(&mut self, item: (T, ()), f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Source§

impl<T> At<(T,)> for BTreeSet<T>
where T: Ord,

Source§

type View = BTreeSet<T>

Source§

fn access_at<R, F>(&mut self, item: (T,), f: F) -> Option<R>
where F: FnOnce(&mut Self) -> R,

Source§

impl<T> At<(T,)> for HashSet<T>
where T: Eq + Hash,

Available on crate feature hashbrown only.
Source§

type View = HashSet<T>

Source§

fn access_at<R, F>(&mut self, item: (T,), f: F) -> Option<R>
where F: FnOnce(&mut Self) -> R,

Source§

impl<T> At<Range<usize>> for Vec<T>

Source§

type View = Vec<T>

Source§

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

Source§

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

Source§

type View = [T]

Source§

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

Source§

impl<T> At<RangeFrom<usize>> for Vec<T>

Source§

type View = Vec<T>

Source§

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

Source§

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

Source§

type View = [T]

Source§

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

Source§

impl<T> At<RangeFull> for Vec<T>

Source§

type View = Vec<T>

Source§

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

Source§

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

Source§

type View = [T]

Source§

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

Source§

impl<T> At<RangeInclusive<usize>> for Vec<T>

Source§

type View = Vec<T>

Source§

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

Source§

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

Source§

type View = [T]

Source§

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

Source§

impl<T> At<RangeTo<usize>> for Vec<T>

Source§

type View = Vec<T>

Source§

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

Source§

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

Source§

type View = [T]

Source§

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

Source§

impl<T> At<RangeToInclusive<usize>> for Vec<T>

Source§

type View = Vec<T>

Source§

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

Source§

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

Source§

type View = [T]

Source§

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

Source§

impl<T> At<usize> for Vec<T>

Source§

type View = T

Source§

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

Source§

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

Source§

type View = T

Source§

fn access_at<R, F>(&mut self, i: usize, f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Implementors§

Source§

impl<'a, I, B, V> At<Bounds<B>> for I
where I: Iterator<Item = &'a mut V>, [&'a mut V]: At<B, View = [&'a mut V]>, V: 'a + ?Sized,

Source§

impl<T> At<Range<usize>> for Slice<T>

Source§

impl<T> At<RangeFrom<usize>> for Slice<T>

Source§

impl<T> At<RangeFull> for Slice<T>

Source§

impl<T> At<RangeInclusive<usize>> for Slice<T>

Source§

impl<T> At<RangeTo<usize>> for Slice<T>

Source§

impl<T> At<RangeToInclusive<usize>> for Slice<T>

Source§

impl<T> At<usize> for Slice<T>

Source§

type View = T