pub struct MemoryContentStore { /* private fields */ }Expand description
In-memory content store backed by a HashMap.
Suitable for the PoC and testing. Not persisted across runs.
Uses RwLock for interior mutability so that the
ContentStore trait methods (which take &self) can mutate
the internal map safely across threads.
§Concurrency
Read operations (get, contains) acquire a read lock.
Write operations (put) acquire a write lock. Multiple
concurrent readers are allowed; writers are exclusive.
§Example
use bcp_encoder::MemoryContentStore;
use bcp_types::ContentStore;
let store = MemoryContentStore::new();
let data = b"fn main() {}";
let hash = store.put(data);
assert_eq!(store.get(&hash).unwrap(), data);
assert!(store.contains(&hash));
assert_eq!(store.len(), 1);Implementations§
Source§impl MemoryContentStore
impl MemoryContentStore
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Return the total bytes stored across all entries.
This counts only the content bytes, not the 32-byte hash
keys or HashMap overhead.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MemoryContentStore
impl RefUnwindSafe for MemoryContentStore
impl Send for MemoryContentStore
impl Sync for MemoryContentStore
impl Unpin for MemoryContentStore
impl UnsafeUnpin for MemoryContentStore
impl UnwindSafe for MemoryContentStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more