Skip to main content

LinksStorage

Trait LinksStorage 

Source
pub trait LinksStorage<T: LinkReference> {
Show 16 methods // Required methods fn create_link(&mut self, source: T, target: T) -> Result<T, LinkError>; fn ensure_link_created(&mut self, index: T) -> Result<T, LinkError>; fn get_link(&self, index: T) -> Option<GenericLink<T>>; fn update_link( &mut self, index: T, source: T, target: T, ) -> Result<GenericLink<T>, LinkError>; fn delete_link(&mut self, index: T) -> Result<GenericLink<T>, LinkError>; fn all_links(&self) -> Vec<GenericLink<T>>; fn flush(&mut self) -> Result<(), LinkError>; // Provided methods fn link_exists(&self, index: T) -> bool { ... } fn update_link_observed( &mut self, index: T, source: T, target: T, observer: &mut dyn FnMut(GenericLink<T>, GenericLink<T>), ) -> Result<GenericLink<T>, LinkError> { ... } fn delete_link_observed( &mut self, index: T, observer: &mut dyn FnMut(GenericLink<T>, GenericLink<T>), ) -> Result<GenericLink<T>, LinkError> { ... } fn query_links( &self, index: Option<T>, source: Option<T>, target: Option<T>, ) -> Vec<GenericLink<T>> { ... } fn search_link(&self, source: T, target: T) -> Option<T> { ... } fn get_or_create_link( &mut self, source: T, target: T, ) -> Result<T, LinkError> { ... } fn links_count(&self) -> usize { ... } fn has_external_changes(&self) -> Result<bool, LinkError> { ... } fn reload(&mut self) -> Result<(), LinkError> { ... }
}
Expand description

A store of links addressed by T, expressed in terms of owned GenericLink<T> values so that both in-memory maps and memory-mapped doublets stores can implement it.

Required Methods§

Creates a new link and returns its address.

Ensures a link exists at index, creating placeholders as needed.

Returns the link stored at index, if any.

Repoints index at source/target, returning the previous state.

Deletes index, returning the link that was removed.

Returns every link in the store.

Source

fn flush(&mut self) -> Result<(), LinkError>

Makes every write durable on disk.

Implementations that keep state in memory write it out here; memory-mapped implementations fsync the backing file. Callers that need crash-consistency guarantees must call this — see the durability notes on each implementation.

Provided Methods§

Returns true when a link exists at index.

Self::update_link, reporting every (before, after) change it made.

A store that resolves duplicate doublets turns one write into a cascade of changes, and the transactions layer has to log each of them or a rollback cannot restore what the write actually did. This is the equivalent of the WriteHandler the C# decorators forward to.

The default implementation reports the single change a store without any policy of its own makes, so implementors only override it when they really can cascade.

Self::delete_link, reporting every (before, after) change it made.

See Self::update_link_observed; a cascading delete removes every link that still referenced index.

Returns every link matching the (optional) index/source/target pattern.

Finds the address of a link with the given source and target.

Returns the address of an existing (source, target) link, creating it when it does not exist yet.

Number of links currently stored.

Source

fn has_external_changes(&self) -> Result<bool, LinkError>

Cheap check for “did another process write to this database since we last read or wrote it?”.

The default implementation reports false, which is correct for stores that are not shared through the filesystem.

Source

fn reload(&mut self) -> Result<(), LinkError>

Re-reads the database from disk, discarding cached state.

The default implementation is a no-op for stores that always read through to their backing storage.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§