Struct libwebnovel_storage::LocalLibrary
source · pub struct LocalLibrary { /* private fields */ }Expand description
A local disk storage.
use tempfile::tempdir;
use libwebnovel_storage::LocalLibrary;
// Dummy path to a config file. If the path does not exist, a default configuration will be created
let config_path = "path/to/toml_config";
let mut library = LocalLibrary::load(config_path).unwrap();
// Add & download a given URL
library
.add("https://www.royalroad.com/fiction/21220/mother-of-learning")
.unwrap();
let novel_urls_list = library.list();
assert_eq!(novel_urls_list.len(), 1);
assert_eq!(
&novel_urls_list[0].to_string(),
"https://www.royalroad.com/fiction/21220/mother-of-learning"
);Implementations§
source§impl LocalLibrary
impl LocalLibrary
sourcepub fn load(config_path: impl Into<PathBuf>) -> Result<Self, LibraryError>
pub fn load(config_path: impl Into<PathBuf>) -> Result<Self, LibraryError>
Attempts to create a new Self from a config file.
use libwebnovel_storage::LocalLibrary;
let config_path = "path/to/toml_config";
let library = LocalLibrary::load(config_path).unwrap();sourcepub fn persist(&self) -> Result<(), LibraryError>
pub fn persist(&self) -> Result<(), LibraryError>
Saves the current config to disk.
use std::path::Path;
use libwebnovel_storage::LocalLibrary;
let config_path_str = "/tmp/libwebnovel/config.toml";
let config_path = Path::new(config_path_str);
let library = LocalLibrary::load(config_path_str.clone()).unwrap();
let config_path = Path::new(&config_path_str);
assert!(!config_path.exists());
library.persist().unwrap();
assert!(config_path.exists());sourcepub fn add(&mut self, url: &str) -> Result<String, LibraryError>
pub fn add(&mut self, url: &str) -> Result<String, LibraryError>
Adds a new webnovel to watch. Will also call Novel::update.
sourcepub fn update(&mut self) -> Result<(), Vec<LibraryError>>
pub fn update(&mut self) -> Result<(), Vec<LibraryError>>
Updates all watched novels. If at least one error has been encountered during update.
sourcepub fn remove(&mut self, url: &str) -> Result<(), LibraryError>
pub fn remove(&mut self, url: &str) -> Result<(), LibraryError>
Removes a webnovel frow the watchlist and deletes local content. If there are duplicates in the novels list, only the first found will be removed and deleted.
sourcepub fn novels_mut(&mut self) -> &mut Vec<Novel>
pub fn novels_mut(&mut self) -> &mut Vec<Novel>
Returns a mutable reference to the internal novels vector
Trait Implementations§
source§impl Debug for LocalLibrary
impl Debug for LocalLibrary
source§impl Default for LocalLibrary
impl Default for LocalLibrary
source§impl<'de> Deserialize<'de> for LocalLibrary
impl<'de> Deserialize<'de> for LocalLibrary
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for LocalLibrary
impl !RefUnwindSafe for LocalLibrary
impl !Send for LocalLibrary
impl !Sync for LocalLibrary
impl Unpin for LocalLibrary
impl UnwindSafe for LocalLibrary
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more