Skip to main content

objects/store/
source.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Store bridges for read-only object source traits.
3
4#[cfg(any(test, feature = "memory-backend"))]
5use super::InMemoryStore;
6use super::{AnyStore, FsStore, ObjectStore, Result};
7use crate::object::{Blob, ContentHash, State, StateId, Tree};
8
9#[cfg(feature = "async-source")]
10pub use crate::object::AsyncObjectSource;
11pub use crate::object::ObjectSource;
12
13macro_rules! impl_object_source {
14    ($store:ty) => {
15        impl ObjectSource for $store {
16            #[inline]
17            fn get_tree(&self, hash: &ContentHash) -> Result<Option<Tree>> {
18                ObjectStore::get_tree(self, hash)
19            }
20
21            #[inline]
22            fn get_state(&self, id: &StateId) -> Result<Option<State>> {
23                ObjectStore::get_state(self, id)
24            }
25
26            #[inline]
27            fn get_blob(&self, hash: &ContentHash) -> Result<Option<Blob>> {
28                ObjectStore::get_blob(self, hash)
29            }
30
31            #[inline]
32            fn decoded_blob_len(&self, hash: &ContentHash) -> Result<Option<u64>> {
33                ObjectStore::blob_size(self, hash)
34            }
35
36            #[inline]
37            fn get_blob_bytes(&self, hash: &ContentHash) -> Result<Option<bytes::Bytes>> {
38                ObjectStore::get_blob_bytes(self, hash)
39            }
40        }
41    };
42}
43
44impl_object_source!(AnyStore);
45impl_object_source!(FsStore);
46#[cfg(any(test, feature = "memory-backend"))]
47impl_object_source!(InMemoryStore);