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 get_blob_bytes(&self, hash: &ContentHash) -> Result<Option<bytes::Bytes>> {
16 Ok(self
17 .get_blob(hash)?
18 .map(|blob| bytes::Bytes::from(blob.into_content())))
19 }
20}
21
22#[cfg(feature = "async-source")]
23#[allow(async_fn_in_trait)]
24pub trait AsyncObjectSource {
25 async fn get_tree(&self, hash: &ContentHash) -> Result<Option<Tree>>;
26 async fn get_state(&self, id: &StateId) -> Result<Option<State>>;
27 async fn get_blob(&self, hash: &ContentHash) -> Result<Option<Blob>>;
28}