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§
Sourcefn access_at<R, F>(&mut self, i: Index, f: F) -> Option<R>
fn access_at<R, F>(&mut self, i: Index, f: F) -> Option<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", so this trait is not object safe.