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 directories::BaseDirs;
use libwebnovel_storage::LocalLibrary;
let config_path = "path/to/config.toml";
let library = LocalLibrary::load(config_path).unwrap(); // If the path doesn't exist, a
// default configuration will be
// loaded
// Get the default data directory on this platform
let basedirs = BaseDirs::new().unwrap();
let data_dir = basedirs.data_dir().join(env!["CARGO_PKG_NAME"]);
assert_eq!(library.base_path(), data_dir);Sourcepub fn set_base_path(
&mut self,
base_path: impl Into<PathBuf> + AsRef<Path>,
) -> Result<(), LibraryError>
pub fn set_base_path( &mut self, base_path: impl Into<PathBuf> + AsRef<Path>, ) -> Result<(), LibraryError>
Changes the library base data path, moving existing content if necessary.
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. Won’t call [self.update()]. Returns the
title of the novel.
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 from 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().