January 2019
Intermediate to advanced
520 pages
14h 32m
English
The following struct wraps an address of CacheActor:
#[derive(Clone)]pub struct CacheLink { addr: Addr<CacheActor>,}
The constructor only fills this addr field with an Addr value:
impl CacheLink { pub fn new(addr: Addr<CacheActor>) -> Self { Self { addr } }}
We need a CacheLink wrapping struct to add methods to get access to caching features, but need to hide the implementation details and message interchange. First, we need a method to get cached values:
pub fn get_value(&self, path: &str) -> Box<Future<Item = Option<Vec<u8>>, Error = Error>> { let msg = GetValue { path: path.to_owned(), }; let fut = self.addr.send(msg) .from_err::<Error>() .and_then(|x| x.map_err(Error::from)); Box::new(fut)}
The preceding function creates ...
Read now
Unlock full access