Skip to main content

MemoryContentStore

Struct MemoryContentStore 

Source
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

Source

pub fn new() -> Self

Create an empty in-memory content store.

Source

pub fn len(&self) -> usize

Return the number of unique entries in the store.

Source

pub fn is_empty(&self) -> bool

Return true if the store contains no entries.

Source

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§

Source§

impl ContentStore for MemoryContentStore

Source§

fn get(&self, hash: &[u8; 32]) -> Option<Vec<u8>>

Retrieve content by its BLAKE3 hash. Read more
Source§

fn put(&self, content: &[u8]) -> [u8; 32]

Store content and return its BLAKE3 hash. Read more
Source§

fn contains(&self, hash: &[u8; 32]) -> bool

Check whether a hash exists in the store without retrieving the content.
Source§

impl Default for MemoryContentStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.