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(db_path: &str, trace: bool) -> Result<Self>

Creates a new LinkStorage instance

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§

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