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
impl LinkStorage
Sourcepub fn new<P: AsRef<Path>>(db_path: P, trace: bool) -> Result<Self>
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.
Sourcepub fn database_path(&self) -> &Path
pub fn database_path(&self) -> &Path
The database file this storage reads from and writes to.
Sourcepub fn observed_revision(&self) -> StorageRevision
pub fn observed_revision(&self) -> StorageRevision
The revision of the database file observed at the last load or save.
Sourcepub fn refresh_observed_revision(&mut self) -> Result<(), LinkError>
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.
Sourcepub fn reload_from_disk(&mut self) -> Result<()>
pub fn reload_from_disk(&mut self) -> Result<()>
Discards in-memory state and re-reads the database file.
Sourcepub fn create(&mut self, source: u32, target: u32) -> u32
pub fn create(&mut self, source: u32, target: u32) -> u32
Creates a new link and returns its ID
Sourcepub fn ensure_created(&mut self, id: u32) -> u32
pub fn ensure_created(&mut self, id: u32) -> u32
Creates a link with a specific ID, ensuring all links up to that ID exist
Sourcepub fn update(&mut self, id: u32, source: u32, target: u32) -> Result<Link>
pub fn update(&mut self, id: u32, source: u32, target: u32) -> Result<Link>
Updates a link’s source and target
Sourcepub fn query(
&self,
index: Option<u32>,
source: Option<u32>,
target: Option<u32>,
) -> Vec<&Link> ⓘ
pub fn query( &self, index: Option<u32>, source: Option<u32>, target: Option<u32>, ) -> Vec<&Link> ⓘ
Returns all links matching a query pattern
Sourcepub fn search(&self, source: u32, target: u32) -> Option<u32>
pub fn search(&self, source: u32, target: u32) -> Option<u32>
Searches for a link with the given source and target
Sourcepub fn get_or_create(&mut self, source: u32, target: u32) -> u32
pub fn get_or_create(&mut self, source: u32, target: u32) -> u32
Gets or creates a link with the given source and target
Sourcepub fn format_lino(&self, link: &Link) -> String
pub fn format_lino(&self, link: &Link) -> String
Formats a link as LiNo suitable for database export.
Sourcepub fn lino_lines(&self) -> Vec<String>
pub fn lino_lines(&self) -> Vec<String>
Returns all database links as sorted LiNo lines.
Sourcepub fn write_lino_output<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn write_lino_output<P: AsRef<Path>>(&self, path: P) -> Result<()>
Writes the complete database as LiNo.
Sourcepub fn format_structure(&self, id: u32) -> Result<String>
pub fn format_structure(&self, id: u32) -> Result<String>
Formats the structure of a link
Sourcepub fn print_all_links(&self)
pub fn print_all_links(&self)
Prints all links
Sourcepub fn print_change(&self, before: &Option<Link>, after: &Option<Link>)
pub fn print_change(&self, before: &Option<Link>, after: &Option<Link>)
Prints a change (before -> after)
Sourcepub fn get_or_create_named(&mut self, name: &str) -> u32
pub fn get_or_create_named(&mut self, name: &str) -> u32
Gets or creates a link with a name
Sourcepub fn get_by_name(&self, name: &str) -> Option<u32>
pub fn get_by_name(&self, name: &str) -> Option<u32>
Gets a link ID by name
Sourcepub fn remove_name(&mut self, id: u32)
pub fn remove_name(&mut self, id: u32)
Removes the name for a link
Sourcepub fn is_trace_enabled(&self) -> bool
pub fn is_trace_enabled(&self) -> bool
Returns true if trace mode is enabled
Trait Implementations§
Source§impl LinksStorage<u32> for LinkStorage
impl LinksStorage<u32> for LinkStorage
Source§fn create_link(&mut self, source: u32, target: u32) -> Result<u32, LinkError>
fn create_link(&mut self, source: u32, target: u32) -> Result<u32, LinkError>
Source§fn ensure_link_created(&mut self, index: u32) -> Result<u32, LinkError>
fn ensure_link_created(&mut self, index: u32) -> Result<u32, LinkError>
index, creating placeholders as needed.Source§fn get_link(&self, index: u32) -> Option<GenericLink<u32>>
fn get_link(&self, index: u32) -> Option<GenericLink<u32>>
index, if any.Source§fn link_exists(&self, index: u32) -> bool
fn link_exists(&self, index: u32) -> bool
true when a link exists at index.Source§fn update_link(
&mut self,
index: u32,
source: u32,
target: u32,
) -> Result<GenericLink<u32>, LinkError>
fn update_link( &mut self, index: u32, source: u32, target: u32, ) -> Result<GenericLink<u32>, LinkError>
index at source/target, returning the previous state.Source§fn delete_link(&mut self, index: u32) -> Result<GenericLink<u32>, LinkError>
fn delete_link(&mut self, index: u32) -> Result<GenericLink<u32>, LinkError>
index, returning the link that was removed.Source§fn query_links(
&self,
index: Option<u32>,
source: Option<u32>,
target: Option<u32>,
) -> Vec<GenericLink<u32>>
fn query_links( &self, index: Option<u32>, source: Option<u32>, target: Option<u32>, ) -> Vec<GenericLink<u32>>
Source§fn search_link(&self, source: u32, target: u32) -> Option<u32>
fn search_link(&self, source: u32, target: u32) -> Option<u32>
Source§fn get_or_create_link(
&mut self,
source: u32,
target: u32,
) -> Result<u32, LinkError>
fn get_or_create_link( &mut self, source: u32, target: u32, ) -> Result<u32, LinkError>
(source, target) link,
creating it when it does not exist yet.