fn load_bytes_with<
    T: Send + 'static,
    FLocal: Fn(Bytes) -> Result<T, String> + Send + Sync + 'static,
    FRemote: Fn(Bytes) -> Result<T, String> + Send + Sync + 'static,
  >(
    &self,
    entry_type: EntryType,
    digest: Digest,
    f_local: FLocal,
    f_remote: FRemote,
  ) -> BoxFuture<Option<T>, String> {
    let local = self.local.clone();
    let maybe_remote = self.remote.clone();
    self
      .local
      .load_bytes_with(entry_type, digest, f_local)
      .and_then(
        move |maybe_local_value| match (maybe_local_value, maybe_remote) {
          (Some(value_result), _) => future::done(value_result.map(Some)).to_boxed(),
          (None, None) => future::ok(None).to_boxed(),
          (None, Some(remote)) => remote
            .load_bytes_with(entry_type, digest, move |bytes: Bytes| bytes)
            .and_then(move |maybe_bytes: Option<Bytes>| match maybe_bytes {
              Some(bytes) => future::done(f_remote(bytes.clone()))
                .and_then(move |value| {
                  local
                    .store_bytes(entry_type, bytes, true)
                    .and_then(move |stored_digest| {
                      if digest == stored_digest {
                        Ok(Some(value))
                      } else {
                        Err(format!(
                          "CAS gave wrong digest: expected {:?}, got {:?}",
                          digest, stored_digest
                        ))
                      }
                    })
                })
                .to_boxed(),
              None => future::ok(None).to_boxed(),
            })
            .to_boxed(),
        },
      )
      .to_boxed()
  }
///
/// Loads bytes from remote cas if required and possible (i.e. if remote is configured). Takes
/// two functions f_local and f_remote. These functions are any validation or transformations you
/// want to perform on the bytes received from the local and remote cas (if remote is configured).
///
Loads bytes from remote cas if required and possible .
Loads bytes from remote cas if required and possible .
fn load_bytes_with<
    T: Send + 'static,
    FLocal: Fn(Bytes) -> Result<T, String> + Send + Sync + 'static,
    FRemote: Fn(Bytes) -> Result<T, String> + Send + Sync + 'static,
  >(
    &self,
    entry_type: EntryType,
    digest: Digest,
    f_local: FLocal,
    f_remote: FRemote,
  ) -> BoxFuture<Option<T>, String> {
    let local = self.local.clone();
    let maybe_remote = self.remote.clone();
    self
      .local
      .load_bytes_with(entry_type, digest, f_local)
      .and_then(
        move |maybe_local_value| match (maybe_local_value, maybe_remote) {
          (Some(value_result), _) => future::done(value_result.map(Some)).to_boxed(),
          (None, None) => future::ok(None).to_boxed(),
          (None, Some(remote)) => remote
            .load_bytes_with(entry_type, digest, move |bytes: Bytes| bytes)
            .and_then(move |maybe_bytes: Option<Bytes>| match maybe_bytes {
              Some(bytes) => future::done(f_remote(bytes.clone()))
                .and_then(move |value| {
                  local
                    .store_bytes(entry_type, bytes, true)
                    .and_then(move |stored_digest| {
                      if digest == stored_digest {
                        Ok(Some(value))
                      } else {
                        Err(format!(
                          "CAS gave wrong digest: expected {:?}, got {:?}",
                          digest, stored_digest
                        ))
                      }
                    })
                })
                .to_boxed(),
              None => future::ok(None).to_boxed(),
            })
            .to_boxed(),
        },
      )
      .to_boxed()
  }
fn load_bytes_with < T : Send + ' static , FLocal : Fn ( Bytes ) -> Result < T , String > + Send + Sync + ' static , FRemote : Fn ( Bytes ) -> Result < T , String > + Send + Sync + ' static , > ( & self , entry_type : EntryType , digest : Digest , f_local : FLocal , f_remote : FRemote , ) -> BoxFuture < Option < T > , String > { let local = self . local . clone ( ) ; let maybe_remote = self . remote . clone ( ) ; self . local . load_bytes_with ( entry_type , digest , f_local ) . and_then ( move | maybe_local_value | match ( maybe_local_value , maybe_remote ) { ( Some ( value_result ) , _ ) => future :: done ( value_result . map ( Some ) ) . to_boxed ( ) , ( None , None ) => future :: ok ( None ) . to_boxed ( ) , ( None , Some ( remote ) ) => remote . load_bytes_with ( entry_type , digest , move | bytes : Bytes | bytes ) . and_then ( move | maybe_bytes : Option < Bytes > | match maybe_bytes { Some ( bytes ) => future :: done ( f_remote ( bytes . clone ( ) ) ) . and_then ( move | value | { local . store_bytes ( entry_type , bytes , true ) . and_then ( move | stored_digest | { if digest == stored_digest { Ok ( Some ( value ) ) } else { Err ( format ! ( " " digest stored_digest ) ) } } ) } ) . to_boxed ( ) , None => future :: ok ( None ) . to_boxed ( ) , } ) . to_boxed ( ) , } , ) . to_boxed ( ) }
Loads bytes from remote cas if required and possible (i.e.
Loads bytes from remote cas if required and possible ( i . e .
&self
entry_type
EntryType
digest
Digest
f_local
FLocal
f_remote
FRemote
&self
entry_type
EntryType
digest
Digest
f_local
FLocal
f_remote
FRemote