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
impl BookmarkManager
Sourcepub fn new() -> Result<Self>
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.
Sourcepub fn save_bookmark(
&mut self,
name: String,
query: String,
description: Option<String>,
) -> Result<()>
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.
Sourcepub fn get_bookmark(&self, name: &str) -> Option<&Bookmark>
pub fn get_bookmark(&self, name: &str) -> Option<&Bookmark>
Sourcepub fn list_bookmarks(&self)
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.
Sourcepub fn delete_bookmark(&mut self, name: &str) -> Result<bool>
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.
Sourcepub fn show_bookmark(&self, name: &str) -> Option<()>
pub fn show_bookmark(&self, name: &str) -> Option<()>
Trait Implementations§
Source§impl Clone for BookmarkManager
impl Clone for BookmarkManager
Source§fn clone(&self) -> BookmarkManager
fn clone(&self) -> BookmarkManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more