pub struct WordchipperDiskCache { /* private fields */ }Expand description
Disk cache for downloaded files.
Implementations§
Source§impl WordchipperDiskCache
impl WordchipperDiskCache
Sourcepub fn init(options: WordchipperDiskCacheOptions) -> Result<Self>
pub fn init(options: WordchipperDiskCacheOptions) -> Result<Self>
Construct a new WordchipperDiskCache.
Sourcepub fn downloader(&self) -> &Downloader
pub fn downloader(&self) -> &Downloader
Get the downloader.
Sourcepub fn cache_path<C, F>(&self, context: &[C], file: F) -> PathBuf
pub fn cache_path<C, F>(&self, context: &[C], file: F) -> PathBuf
Get the cache path for the given key.
- Does not check that the path exists.
- Does not initialize the containing directories.
§Arguments
context- prefix dirs, inserted betweenself.cache_dirandfile.file- the final file name.
Sourcepub fn load_cached_path<C>(
&mut self,
context: &[C],
urls: &[&str],
download: bool,
) -> Result<PathBuf>
pub fn load_cached_path<C>( &mut self, context: &[C], urls: &[&str], download: bool, ) -> Result<PathBuf>
Loads a cached file from a specified path or downloads it if it does not exist.
§Arguments
context: A slice ofCcontaining path-related context used in determining the cache location. These paths are combined to build the cached file’s location.urls: A slice of string references specifying the URLs to download the file from if it is not already cached.download: A boolean flag indicating whether to attempt downloading the file from the provided URLs if it does not already exist in the cache.
§Returns
- Returns a
PathBufpointing to the cached file if it exists or is successfully downloaded. - Returns an error if the file is not found in the cache and downloading is not allowed or fails.
§Errors
- Returns an error if the cached file does not exist and
downloadisfalse. - Returns an error if the downloading process fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WordchipperDiskCache
impl !RefUnwindSafe for WordchipperDiskCache
impl Send for WordchipperDiskCache
impl Sync for WordchipperDiskCache
impl Unpin for WordchipperDiskCache
impl !UnwindSafe for WordchipperDiskCache
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