pub trait Indexing<T, E> {
// Required methods
fn get_at<'a>(&self, root: &'a T, idx: usize) -> &'a E;
fn get_mut_at<'a>(&self, root: &'a mut T, idx: usize) -> &'a mut E;
fn set_at(&self, root: &mut T, idx: usize, value: E);
fn set_mut_at(&self, root: &mut T, idx: usize, f: impl FnOnce(&mut E));
fn set_clone_at(&self, root: &mut T, idx: usize, value: &E)
where E: Clone;
}Expand description
Indexing operations for accessors that focus Vec<E>.
Provided as a blanket impl for Accessor<T, Vec<E>>.
Required Methods§
Sourcefn get_at<'a>(&self, root: &'a T, idx: usize) -> &'a E
fn get_at<'a>(&self, root: &'a T, idx: usize) -> &'a E
Borrow the element at idx immutably.
use pathmod_core::{Accessor, Indexing};
#[derive(Debug)]
struct Bag { items: Vec<i32> }
fn acc_items() -> Accessor<Bag, Vec<i32>> {
fn gr(b: &Bag) -> &Vec<i32> { &b.items }
fn gm(b: &mut Bag) -> &mut Vec<i32> { &mut b.items }
Accessor::from_fns(gr, gm)
}
let b = Bag { items: vec![1,2,3] };
let acc = acc_items();
assert_eq!(*acc.get_at(&b, 1), 2);Sourcefn get_mut_at<'a>(&self, root: &'a mut T, idx: usize) -> &'a mut E
fn get_mut_at<'a>(&self, root: &'a mut T, idx: usize) -> &'a mut E
Borrow the element at idx mutably.
Sourcefn set_at(&self, root: &mut T, idx: usize, value: E)
fn set_at(&self, root: &mut T, idx: usize, value: E)
Set the element at idx by moving value in.
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.