heddle_object_model/object/
source.rs1use super::{Blob, ContentHash, State, StateId, Tree};
5use crate::error::Result;
6
7pub trait ObjectSource {
9 fn get_tree(&self, hash: &ContentHash) -> Result<Option<Tree>>;
10 fn get_state(&self, id: &StateId) -> Result<Option<State>>;
11 fn get_blob(&self, hash: &ContentHash) -> Result<Option<Blob>>;
12
13 fn decoded_blob_len(&self, hash: &ContentHash) -> Result<Option<u64>> {
19 Ok(self.get_blob(hash)?.map(|blob| blob.content().len() as u64))
20 }
21
22 fn get_blob_bytes(&self, hash: &ContentHash) -> Result<Option<bytes::Bytes>> {
24 Ok(self
25 .get_blob(hash)?
26 .map(|blob| bytes::Bytes::from(blob.into_content())))
27 }
28}
29
30#[cfg(feature = "async-source")]
31#[allow(async_fn_in_trait)]
32pub trait AsyncObjectSource {
33 async fn get_tree(&self, hash: &ContentHash) -> Result<Option<Tree>>;
34 async fn get_state(&self, id: &StateId) -> Result<Option<State>>;
35 async fn get_blob(&self, hash: &ContentHash) -> Result<Option<Blob>>;
36}