Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

InMemory

Struct InMemory 

Source
pub struct InMemory { /* private fields */ }
Expand description

A simple in-memory database implementation using a HashMap for storage.

This database is suitable for testing, development, or scenarios where data persistence is not strictly required or is handled externally (e.g., by saving/loading the entire state to/from a file).

It provides basic persistence capabilities via save_to_file and load_from_file, serializing the HashMap to JSON.

Security Note: The device key is stored in memory in plaintext in this implementation. This is acceptable for development and testing but should not be used in production without proper encryption or hardware security module integration.

Implementations§

Source§

impl InMemory

Source

pub fn new() -> Self

Creates a new, empty InMemory database.

Source

pub async fn all_ids(&self) -> Vec<ID>

Returns a vector containing the IDs of all entries currently stored in the database.

Source

pub async fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>

Saves the entire database state (all entries) to a specified file as JSON.

§Arguments
  • path - The path to the file where the state should be saved.
§Returns

A Result indicating success or an I/O or serialization error.

Source

pub async fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Loads the database state from a specified JSON file.

If the file does not exist, a new, empty InMemory database is returned.

§Arguments
  • path - The path to the file from which to load the state.
§Returns

A Result containing the loaded InMemory database or an I/O or deserialization error.

Source

pub fn sort_entries_by_height(&self, _tree: &ID, entries: &mut [Entry])

Sort entries by their height within a tree (exposed for testing)

Heights are stored directly in entries, so this just reads and sorts.

§Arguments
  • _tree - The ID of the tree context (unused, kept for API compatibility)
  • entries - The vector of entries to be sorted in place
Source

pub fn sort_entries_by_subtree_height( &self, _tree: &ID, subtree: &str, entries: &mut [Entry], )

Sort entries by their height within a subtree (exposed for testing)

Heights are stored directly in entries, so this just reads and sorts.

§Arguments
  • _tree - The ID of the tree context (unused, kept for API compatibility)
  • subtree - The name of the subtree context
  • entries - The vector of entries to be sorted in place
Source

pub async fn is_tip(&self, tree: &ID, entry_id: &ID) -> bool

Check if an entry is a tip within its tree (exposed for benchmarks)

An entry is a tip if no other entry in the same tree lists it as a parent.

§Arguments
  • tree - The ID of the tree to check within
  • entry_id - The ID of the entry to check
§Returns

true if the entry is a tip, false otherwise

Trait Implementations§

Source§

impl BackendImpl for InMemory

Source§

fn get<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<Entry>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves an entry by its unique content-addressable ID.

§Arguments
  • id - The ID of the entry to retrieve.
§Returns

A Result containing the Entry if found, or a DatabaseError::EntryNotFound otherwise. Returns an owned copy to support concurrent access with internal synchronization.

Source§

fn get_verification_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<VerificationStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets the verification status of an entry.

§Arguments
  • id - The ID of the entry to check.
§Returns

A Result containing the VerificationStatus if the entry exists, or a DatabaseError::VerificationStatusNotFound otherwise.

Source§

fn update_verification_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, verification_status: VerificationStatus, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates the verification status of an existing entry.

This allows the authentication system to mark entries as verified or failed after they have been stored. Useful for batch verification operations.

§Arguments
  • id - The ID of the entry to update
  • verification_status - The new verification status
§Returns

A Result indicating success or DatabaseError::EntryNotFound if the entry doesn’t exist.

Source§

fn get_entries_by_verification_status<'life0, 'async_trait>( &'life0 self, status: VerificationStatus, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets all entries with a specific verification status.

This is useful for finding unverified entries that need authentication or for security audits.

§Arguments
  • status - The verification status to filter by
§Returns

A Result containing a vector of entry IDs with the specified status.

Source§

fn all_roots<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves the IDs of all top-level root entries stored in the database.

Top-level roots are entries that are themselves roots of a tree (i.e., entry.is_root() is true) and are not part of a larger tree structure tracked by the backend. These represent the starting points of distinct trees managed by the database.

§Returns

A Result containing a vector of top-level root entry IDs or an error.

Source§

fn put<'life0, 'async_trait>( &'life0 self, verification_status: VerificationStatus, entry: Entry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry in the database with the specified verification status. Read more
Source§

fn get_tips<'life0, 'life1, 'async_trait>( &'life0 self, tree: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves the IDs of the tip entries for a given tree. Read more
Source§

fn get_store_tips<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tree: &'life1 ID, subtree: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieves the IDs of the tip entries for a specific store within a given tree. Read more
Source§

fn get_store_tips_up_to_entries<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, subtree: &'life2 str, main_entries: &'life3 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Gets the store tips that exist up to a specific set of main tree entries. Read more
Source§

fn find_merge_base<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, subtree: &'life2 str, entry_ids: &'life3 [ID], ) -> Pin<Box<dyn Future<Output = Result<ID>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Finds the merge base (common dominator) of the given entry IDs within a store. Read more
Source§

fn collect_root_to_target<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, subtree: &'life2 str, target_entry: &'life3 ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Collects all entries from the tree root down to the target entry within a store. Read more
Source§

fn as_any(&self) -> &dyn Any

Returns a reference to the backend instance as a dynamic Any type. Read more
Source§

fn get_tree<'life0, 'life1, 'async_trait>( &'life0 self, tree: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves all entries belonging to a specific tree, sorted topologically. Read more
Source§

fn get_store<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tree: &'life1 ID, subtree: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieves all entries belonging to a specific store within a tree, sorted topologically. Read more
Source§

fn get_tree_from_tips<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tree: &'life1 ID, tips: &'life2 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieves all entries belonging to a specific tree up to the given tips, sorted topologically. Read more
Source§

fn get_store_from_tips<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, subtree: &'life2 str, tips: &'life3 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Retrieves all entries belonging to a specific store within a tree up to the given tips, sorted topologically. Read more
Source§

fn get_instance_metadata<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<InstanceMetadata>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the instance metadata. Read more
Source§

fn set_instance_metadata<'life0, 'life1, 'async_trait>( &'life0 self, metadata: &'life1 InstanceMetadata, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set the instance metadata. Read more
Source§

fn get_cached_crdt_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, entry_id: &'life1 ID, subtree: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get cached CRDT state for a store at a specific entry. Read more
Source§

fn cache_crdt_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, entry_id: &'life1 ID, subtree: &'life2 str, state: String, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Cache CRDT state for a store at a specific entry. Read more
Source§

fn clear_crdt_cache<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear all cached CRDT states. Read more
Source§

fn get_sorted_store_parents<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree_id: &'life1 ID, entry_id: &'life2 ID, subtree: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Get the store parent IDs for a specific entry and store, sorted by height then ID. Read more
Source§

fn get_path_from_to<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, tree_id: &'life1 ID, subtree: &'life2 str, from_id: &'life3 ID, to_ids: &'life4 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Gets all entries between one entry and multiple target entries (exclusive of start, inclusive of targets). Read more
Source§

fn put_verified<'life0, 'async_trait>( &'life0 self, entry: Entry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry with verified status (convenience method for local entries). Read more
Source§

fn put_unverified<'life0, 'async_trait>( &'life0 self, entry: Entry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry with failed verification status (convenience method for sync scenarios). Read more
Source§

impl Debug for InMemory

Source§

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

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

impl Default for InMemory

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for InMemory

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for InMemory

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. 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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<M> Meta for M
where M: Default,