Trait Access

Source
pub trait Access<T> {
    // Required methods
    fn get(&self) -> T;
    fn set(&mut self, new_value: T);

    // Provided method
    fn map<B, F, I>(self, from: F, into: I) -> MapAccess<Self, F, I>
       where Self: Sized,
             F: Fn(T) -> B,
             I: Fn(B) -> T { ... }
}

Required Methods§

Source

fn get(&self) -> T

Source

fn set(&mut self, new_value: T)

Provided Methods§

Source

fn map<B, F, I>(self, from: F, into: I) -> MapAccess<Self, F, I>
where Self: Sized, F: Fn(T) -> B, I: Fn(B) -> T,

Examples found in repository?
examples/example.rs (line 5)
3fn main() {
4    let mut int = 0;
5    let mut string_access = RefAccess::new(&mut int).map(|i| i.to_string(), |s| s.parse().unwrap());
6
7    println!("string: {}", string_access.get());
8    string_access.set("42".to_string());
9    println!("string: {}", string_access.get());
10    println!("int: {}", int);
11}

Implementors§

Source§

impl<A, F, I, T, B> Access<B> for MapAccess<A, F, I>
where A: Access<T>, F: Fn(T) -> B, I: Fn(B) -> T,

Source§

impl<T: Clone> Access<T> for RefAccess<'_, T>