Skip to main content

Interface

Struct Interface 

Source
#[non_exhaustive]
pub struct Interface<S: StorageAdaptor = MainStorage>(/* private fields */);
Expand description

The primary interface for the storage system.

Implementations§

Source§

impl<S: StorageAdaptor> Interface<S>

Source

pub fn add_child_to<D: Data>( parent_id: Id, child: &mut D, ) -> Result<bool, StorageError>

Adds a child entity to a parent’s collection.

Updates Merkle hashes and generates sync actions automatically.

§Errors
  • SerializationError if child can’t be encoded
  • IndexNotFound if parent doesn’t exist
Source

pub fn apply_action(action: Action) -> Result<(), StorageError>

Applies a synchronization action from a remote node.

Handles Add/Update/Delete actions, creating missing ancestors if needed. Generates Compare action for hash verification after applying changes.

§Errors
  • DeserializationError if action data is invalid
  • ActionNotAllowed if Compare action is passed directly
Source

pub fn children_of<D: Data>(parent_id: Id) -> Result<Vec<D>, StorageError>

Retrieves all children in a collection.

Returns deserialized child entities. Order is not guaranteed.

§Errors
  • IndexNotFound if parent doesn’t exist
  • DeserializationError if child data is corrupt
Source

pub fn child_info_for(parent_id: Id) -> Result<Vec<ChildInfo>, StorageError>

Retrieves child metadata without deserializing full data.

Returns IDs, hashes, and timestamps only. More efficient than children_of().

§Errors

Returns error if index lookup fails.

Source

pub fn compare_trees( foreign_entity_data: Option<Vec<u8>>, foreign_index_data: ComparisonData, ) -> Result<(Vec<Action>, Vec<Action>), StorageError>

Compares local and remote entity trees, generating sync actions.

Compares Merkle hashes recursively, producing action lists for both sides. Returns (local_actions, remote_actions) to bring trees into sync.

§Errors

Returns error if index lookup or hash comparison fails.

Source

pub fn compare_affective( data: Option<Vec<u8>>, comparison_data: ComparisonData, ) -> Result<(), StorageError>

Compares entities and automatically applies sync actions locally.

Convenience wrapper around compare_trees() that applies local actions immediately and pushes remote actions to sync queue.

§Errors

Returns error if comparison or action application fails.

Source

pub fn find_by_id<D: Data>(id: Id) -> Result<Option<D>, StorageError>

Finds and deserializes an entity by its unique ID.

Filters out tombstoned (deleted) entities automatically.

§Errors
  • DeserializationError if stored data is corrupt
  • IndexNotFound if entity exists but has no index
Source

pub fn find_by_id_raw(id: Id) -> Option<Vec<u8>>

Finds an entity by ID, returning raw bytes without deserialization.

Note: This does NOT filter deleted entities. Use find_by_id for automatic tombstone filtering.

Source

pub fn get(id: Id) -> Result<Vec<u8>, StorageError>

Gets raw entity data by ID.

This is a simple alias for find_by_id_raw for convenience in tests.

§Errors

Returns IndexNotFound if entity doesn’t exist.

Source

pub fn generate_comparison_data( id: Option<Id>, ) -> Result<ComparisonData, StorageError>

Generates comparison metadata for tree synchronization.

Includes hashes, ancestors, children info. Used by compare_trees().

§Errors

Returns error if index lookup fails.

Source

pub fn has_children(parent_id: Id) -> Result<bool, StorageError>

Checks if a collection has any children.

§Errors

Returns error if index lookup fails.

Source

pub fn parent_of<D: Data>(child_id: Id) -> Result<Option<D>, StorageError>

Retrieves the parent entity of a child.

§Errors

Returns error if index lookup or deserialization fails.

Source

pub fn remove_child_from( parent_id: Id, child_id: Id, ) -> Result<bool, StorageError>

Removes a child from a collection.

Deletes the child entity and generates sync actions automatically.

§Errors

Returns error if parent or child doesn’t exist.

Source

pub fn root<D: Data>() -> Result<Option<D>, StorageError>

Retrieves the root entity.

§Errors

Returns error if deserialization fails.

Source

pub fn commit_root<D: Data>(root: Option<D>) -> Result<(), StorageError>

Saves the root entity and commits sync actions.

Should be called at the end of each transaction. Call once per execution.

§Errors
  • UnexpectedId if root ID doesn’t match
  • SerializationError if encoding fails
Source

pub fn save<D: Data>(entity: &mut D) -> Result<bool, StorageError>

Saves an entity to storage, updating if it exists.

Only saves if entity is dirty. Returns false if not saved due to:

  • Entity not dirty
  • Existing record is newer (last-write-wins guard)

Automatically:

  • Calculates Merkle hashes
  • Updates timestamps
  • Generates sync actions
  • Propagates hash changes up ancestor chain

Note: Use add_child_to() for new children, then save() for subsequent updates.

§Errors
  • SerializationError if encoding fails
  • CannotCreateOrphan if entity has no parent and isn’t root
Source

pub fn save_raw( id: Id, data: Vec<u8>, metadata: Metadata, ) -> Result<Option<[u8; 32]>, StorageError>

Saves raw serialized data with orphan checking.

§Errors
  • CannotCreateOrphan if entity has no parent and isn’t root
Source

pub fn validate() -> Result<(), StorageError>

Validates Merkle tree integrity.

Note: Not yet implemented.

§Errors

Currently panics (unimplemented).

Trait Implementations§

Source§

impl<S: Clone + StorageAdaptor> Clone for Interface<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + StorageAdaptor> Debug for Interface<S>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<S: Default + StorageAdaptor> Default for Interface<S>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S> Forget for Interface<S>

§

impl<S> Freeze for Interface<S>
where PhantomData<S>: Freeze,

§

impl<S> RefUnwindSafe for Interface<S>

§

impl<S> Send for Interface<S>
where PhantomData<S>: Send,

§

impl<S> Sync for Interface<S>
where PhantomData<S>: Sync,

§

impl<S> Unpin for Interface<S>
where PhantomData<S>: Unpin,

§

impl<S> UnsafeUnpin for Interface<S>

§

impl<S> UnwindSafe for Interface<S>

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Reflect for T

Source§

fn as_dyn_ref<'a>(&self) -> &(dyn Reflect + 'a)
where T: 'a,

Source§

fn as_dyn_mut<'a>(&mut self) -> &mut (dyn Reflect + 'a)
where T: 'a,

Source§

fn as_dyn_box<'a>(self: Box<T>) -> Box<dyn Reflect + 'a>
where T: 'a,

Source§

fn as_dyn_rc<'a>(self: Rc<T>) -> Rc<dyn Reflect + 'a>
where T: 'a,

Source§

fn as_dyn_arc<'a>(self: Arc<T>) -> Arc<dyn Reflect + 'a> ⓘ
where T: 'a,

Source§

fn type_id(&self) -> TypeId

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> ReflectExt for T
where T: Reflect + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: Reflect + ?Sized,

Source§

fn type_id() -> TypeId

Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: Reflect,

Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: Reflect,

Source§

fn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Reflect,

Source§

fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Reflect,

Source§

fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Reflect,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more