Skip to main content

Store

Struct Store 

pub struct Store { /* private fields */ }
Expand description

A content-addressed object store rooted at a .cadvm/objects directory.

Implementations§

§

impl Store

pub fn open(objects_root: impl Into<PathBuf>) -> Result<Store, StoreError>

Open a store rooted at the given objects directory. The directory and its category sub-directories are created if missing.

pub fn has(&self, category: Category, id: &ObjectId) -> bool

Whether an object with this id already exists in the given category.

pub fn has_object(&self, id: &ObjectId) -> bool

Convenience: does this blob exist?

pub fn put( &self, category: Category, bytes: &[u8], ) -> Result<ObjectId, StoreError>

Store raw bytes in the given category and return their content id.

Writing is atomic and idempotent: if the object already exists the write is skipped entirely.

pub fn put_bytes(&self, bytes: &[u8]) -> Result<ObjectId, StoreError>

Store a raw blob and return its id (level-1 dedup).

pub fn get( &self, category: Category, id: &ObjectId, ) -> Result<Vec<u8>, StoreError>

Read the raw bytes of a stored object.

pub fn get_bytes(&self, id: &ObjectId) -> Result<Vec<u8>, StoreError>

Read a stored blob.

pub fn put_json<T>( &self, category: Category, value: &T, ) -> Result<ObjectId, StoreError>
where T: Serialize,

Store a JSON-serializable object content-addressed and return its id.

pub fn get_json<T>( &self, category: Category, id: &ObjectId, ) -> Result<T, StoreError>
where T: for<'de> Deserialize<'de>,

Read and deserialize a JSON object.

pub fn put_file_content(&self, content: &[u8]) -> Result<BlobRef, StoreError>

Write a file’s content into the store, producing a BlobRef.

The file is split into fixed 256 KiB chunks, each stored content-addressed so identical chunks across files/versions are shared. raw_hash is the BLAKE3 hash of the whole file and serves purely as a content identity (used for dedup keys and status comparisons) — the full file is not stored as a standalone blob, so there is no on-disk duplication between a raw blob and its chunks.

pub fn read_file_content( &self, blob_ref: &BlobRef, ) -> Result<Vec<u8>, StoreError>

Reconstruct a file’s content from a BlobRef by concatenating its chunks.

pub fn read_file_content_from_chunks( &self, blob_ref: &BlobRef, ) -> Result<Vec<u8>, StoreError>

Reconstruct a file’s content from its chunks. Equivalent to read_file_content; kept as an explicit name for tests that exercise the chunk path directly.

pub fn list(&self, category: Category) -> Result<Vec<ObjectId>, StoreError>

Iterate over the ids of every stored object in a category.

pub fn remove( &self, category: Category, id: &ObjectId, ) -> Result<bool, StoreError>

Delete an object. Used by gc --prune; returns Ok(false) if absent.

Trait Implementations§

§

impl Clone for Store

§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Store

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.