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