Skip to main content

LinkStorage

Struct LinkStorage 

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

LinkStorage provides persistent storage for links Corresponds to the storage functionality in NamedLinksDecorator in C#

Implementations§

Source§

impl LinkStorage

Source

pub fn new<P: AsRef<Path>>(db_path: P, trace: bool) -> Result<Self>

Creates a new LinkStorage instance

The database location is accepted as any AsRef<Path>, so embedding applications can pass a PathBuf (or an OsStr on platforms with non-UTF-8 paths) instead of a &str.

Source

pub fn database_path(&self) -> &Path

The database file this storage reads from and writes to.

Source

pub fn observed_revision(&self) -> StorageRevision

The revision of the database file observed at the last load or save.

Source

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

Re-reads the database file’s revision fingerprint, marking the current on-disk state as “seen” for LinksStorage::has_external_changes.

Source

pub fn reload_from_disk(&mut self) -> Result<()>

Discards in-memory state and re-reads the database file.

Source

pub fn save(&self) -> Result<()>

Saves all links to the database file

Source

pub fn create(&mut self, source: u32, target: u32) -> u32

Creates a new link and returns its ID

Source

pub fn ensure_created(&mut self, id: u32) -> u32

Creates a link with a specific ID, ensuring all links up to that ID exist

Source

pub fn get(&self, id: u32) -> Option<&Link>

Gets a link by ID

Source

pub fn exists(&self, id: u32) -> bool

Checks if a link exists

Source

pub fn update(&mut self, id: u32, source: u32, target: u32) -> Result<Link>

Updates a link’s source and target

Source

pub fn delete(&mut self, id: u32) -> Result<Link>

Deletes a link by ID

Source

pub fn all(&self) -> Vec<&Link>

Returns all links

Source

pub fn query( &self, index: Option<u32>, source: Option<u32>, target: Option<u32>, ) -> Vec<&Link>

Returns all links matching a query pattern

Source

pub fn search(&self, source: u32, target: u32) -> Option<u32>

Searches for a link with the given source and target

Source

pub fn get_or_create(&mut self, source: u32, target: u32) -> u32

Gets or creates a link with the given source and target

Source

pub fn format(&self, link: &Link) -> String

Formats a link for display

Source

pub fn format_lino(&self, link: &Link) -> String

Formats a link as LiNo suitable for database export.

Source

pub fn lino_lines(&self) -> Vec<String>

Returns all database links as sorted LiNo lines.

Source

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

Writes the complete database as LiNo.

Source

pub fn format_structure(&self, id: u32) -> Result<String>

Formats the structure of a link

Prints all links

Source

pub fn print_change(&self, before: &Option<Link>, after: &Option<Link>)

Prints a change (before -> after)

Source

pub fn get_or_create_named(&mut self, name: &str) -> u32

Gets or creates a link with a name

Source

pub fn set_name(&mut self, id: u32, name: &str)

Sets the name for a link

Source

pub fn get_name(&self, id: u32) -> Option<&String>

Gets the name of a link

Source

pub fn get_by_name(&self, name: &str) -> Option<u32>

Gets a link ID by name

Source

pub fn remove_name(&mut self, id: u32)

Removes the name for a link

Source

pub fn is_trace_enabled(&self) -> bool

Returns true if trace mode is enabled

Trait Implementations§

Source§

impl LinksStorage<u32> for LinkStorage

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.
Returns true when a link exists at index.
Repoints index at source/target, returning the previous state.
Deletes index, returning the link that was removed.
Returns every link in the store.
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.
Source§

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

Makes every write durable on disk. Read more
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?”. Read more
Source§

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

Re-reads the database from disk, discarding cached state. Read more
Number of links currently stored.
Source§

impl LinksStorageRef<u32> for LinkStorage

Borrows the link stored at index.
Borrows every link in the store.
Borrows every link matching the (optional) index/source/target pattern.
Source§

fn create(&mut self, source: u32, target: u32) -> u32

Source§

fn ensure_created(&mut self, id: u32) -> u32

Source§

fn exists(&mut self, id: u32) -> bool

Source§

fn update(&mut self, id: u32, source: u32, target: u32) -> Result<Link>

Source§

fn delete(&mut self, id: u32) -> Result<Link>

Source§

fn search(&mut self, source: u32, target: u32) -> Option<u32>

Source§

fn get_or_create(&mut self, source: u32, target: u32) -> u32

Source§

fn get_name(&mut self, id: u32) -> Result<Option<String>>

Source§

fn set_name(&mut self, id: u32, name: &str) -> Result<u32>

Source§

fn get_by_name(&mut self, name: &str) -> Result<Option<u32>>

Source§

fn remove_name(&mut self, id: u32) -> Result<()>

Source§

fn save(&mut self) -> Result<()>

Source§

fn get_or_create_named(&mut self, name: &str) -> Result<u32>

Source§

fn try_ensure_created(&mut self, id: u32) -> Result<u32>

Source§

fn format_reference(&mut self, id: u32) -> Result<String>

Source§

fn format_lino(&mut self, link: &Link) -> Result<String>

Source§

fn lino_lines(&mut self) -> Result<Vec<String>>

Source§

fn write_lino_output<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Source§

fn print_all_lino(&mut self) -> Result<()>

Source§

fn print_change_lino( &mut self, before: &Option<Link>, after: &Option<Link>, ) -> Result<()>

Source§

fn format_structure(&mut self, id: u32) -> Result<String>

Source§

fn format_structure_recursive( &mut self, id: u32, visited: &mut HashSet<u32>, ) -> Result<String>

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 = !

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.