Struct BookmarkManager

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

Manages the collection of bookmarks, including loading from and saving to a file.

This struct is the main entry point for all bookmark-related operations. It holds the bookmarks in a HashMap and manages the file I/O, including backups and atomic saves.

Implementations§

Source§

impl BookmarkManager

Source

pub fn new() -> Result<Self>

Creates a new BookmarkManager instance.

This function initializes the manager by determining the path for the bookmarks file and loading any existing bookmarks from it. It will create the necessary directories if they don’t exist.

§Returns

A Result containing the new BookmarkManager instance, or an Err if the bookmarks file cannot be read or parsed.

Source

pub fn save_bookmark( &mut self, name: String, query: String, description: Option<String>, ) -> Result<()>

Saves or updates a bookmark.

This function adds a new bookmark or updates an existing one with the same name. It performs validation on the name and query, sets the timestamps, and then persists the entire bookmark collection to the file.

§Arguments
  • name - The unique name for the bookmark.
  • query - The SQL query to be saved.
  • description - An optional description for the bookmark.
§Returns

A Result which is Ok(()) on success, or an Err if validation or saving fails.

Source

pub fn get_bookmark(&self, name: &str) -> Option<&Bookmark>

Retrieves a bookmark by its name.

§Arguments
  • name - The name of the bookmark to retrieve.
§Returns

An Option containing a reference to the Bookmark if found, otherwise None.

Source

pub fn list_bookmarks(&self)

Lists all saved bookmarks in a formatted table.

This function prints a user-friendly table of all bookmarks to the console, including their name, description, timestamps, and a preview of the query.

Source

pub fn delete_bookmark(&mut self, name: &str) -> Result<bool>

Deletes a bookmark by its name.

This function removes a bookmark from the collection and then saves the updated collection to the file.

§Arguments
  • name - The name of the bookmark to delete.
§Returns

A Result containing true if the bookmark was found and deleted, false if it was not found, or an Err if the save operation fails.

Source

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

Displays the full details of a single bookmark.

This function prints all information about a specific bookmark to the console, including the full query.

§Arguments
  • name - The name of the bookmark to show.
§Returns

Some(()) if the bookmark was found and displayed, otherwise None.

Trait Implementations§

Source§

impl Clone for BookmarkManager

Source§

fn clone(&self) -> BookmarkManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V