[−][src]Trait smart_access::At
A smart access protocol.
It is intended to be used through a Cps
-bounded type.
Associated Types
Loading content...Required methods
fn access_at<R, F>(&mut self, i: Index, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
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
.
Implementations on Foreign Types
impl<T> At<usize> for [T]
[src]
type View = T
fn access_at<R, F>(&mut self, i: usize, f: F) -> Option<R> where
F: FnOnce(&mut T) -> R,
[src]
F: FnOnce(&mut T) -> R,
impl<T> At<Range<usize>> for [T]
[src]
type View = [T]
fn access_at<R, F>(&mut self, i: Range<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeFrom<usize>> for [T]
[src]
type View = [T]
fn access_at<R, F>(&mut self, i: RangeFrom<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeFull> for [T]
[src]
type View = [T]
fn access_at<R, F>(&mut self, _: RangeFull, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeInclusive<usize>> for [T]
[src]
type View = [T]
fn access_at<R, F>(&mut self, i: RangeInclusive<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeTo<usize>> for [T]
[src]
type View = [T]
fn access_at<R, F>(&mut self, i: RangeTo<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeToInclusive<usize>> for [T]
[src]
type View = [T]
fn access_at<R, F>(&mut self, i: RangeToInclusive<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<()> for Option<T>
[src]
type View = T
fn access_at<R, F>(&mut self, _: (), f: F) -> Option<R> where
F: FnOnce(&mut T) -> R,
[src]
F: FnOnce(&mut T) -> R,
impl<T, S> At<()> for Result<T, S>
[src]
type View = T
fn access_at<R, F>(&mut self, _: (), f: F) -> Option<R> where
F: FnOnce(&mut T) -> R,
[src]
F: FnOnce(&mut T) -> R,
impl<T> At<usize> for Vec<T>
[src]
type View = T
fn access_at<R, F>(&mut self, i: usize, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<Range<usize>> for Vec<T>
[src]
type View = Vec<T>
fn access_at<R, F>(&mut self, i: Range<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeFrom<usize>> for Vec<T>
[src]
type View = Vec<T>
fn access_at<R, F>(&mut self, i: RangeFrom<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeFull> for Vec<T>
[src]
type View = Vec<T>
fn access_at<R, F>(&mut self, _: RangeFull, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeInclusive<usize>> for Vec<T>
[src]
type View = Vec<T>
fn access_at<R, F>(&mut self, i: RangeInclusive<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeTo<usize>> for Vec<T>
[src]
type View = Vec<T>
fn access_at<R, F>(&mut self, i: RangeTo<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<T> At<RangeToInclusive<usize>> for Vec<T>
[src]
type View = Vec<T>
fn access_at<R, F>(&mut self, i: RangeToInclusive<usize>, f: F) -> Option<R> where
F: FnOnce(&mut Self::View) -> R,
[src]
F: FnOnce(&mut Self::View) -> R,
impl<'_, Q: ?Sized, K, V> At<&'_ Q> for HashMap<K, V> where
K: Borrow<Q> + Eq + Hash,
Q: Eq + Hash,
[src]
K: Borrow<Q> + Eq + Hash,
Q: Eq + Hash,
type View = V
fn access_at<R, F>(&mut self, i: &Q, f: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
[src]
F: FnOnce(&mut V) -> R,
impl<K, V> At<(K, V)> for HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
type View = V
fn access_at<R, F>(&mut self, kv: (K, V), f: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
[src]
F: FnOnce(&mut V) -> R,
impl<'_, Q: ?Sized, K, V> At<&'_ Q> for BTreeMap<K, V> where
K: Borrow<Q> + Ord,
Q: Ord,
[src]
K: Borrow<Q> + Ord,
Q: Ord,
type View = V
fn access_at<R, F>(&mut self, i: &Q, f: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
[src]
F: FnOnce(&mut V) -> R,
impl<K, V> At<(K, V)> for BTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
type View = V
fn access_at<R, F>(&mut self, kv: (K, V), f: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
[src]
F: FnOnce(&mut V) -> R,