pub struct PluginCache { /* private fields */ }Expand description
Content-addressed cache that tracks file hashes so plugins can skip unchanged files across incremental builds.
Stores path → content_hash mappings and persists to
.ssg-plugin-cache.json in the site directory.
Implementations§
Source§impl PluginCache
impl PluginCache
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty cache.
§Examples
use ssg::plugin::PluginCache;
use std::path::Path;
let c = PluginCache::new();
assert!(c.has_changed(Path::new("any.path")));Sourcepub fn load(site_dir: &Path) -> Self
pub fn load(site_dir: &Path) -> Self
Loads a cache from site_dir/.ssg-plugin-cache.json.
Returns an empty cache if the file does not exist or cannot be parsed.
§Examples
use ssg::plugin::PluginCache;
use tempfile::tempdir;
let dir = tempdir().unwrap();
// Missing cache file ⇒ empty cache, no error.
let _c = PluginCache::load(dir.path());Sourcepub fn save(&self, site_dir: &Path) -> Result<(), SsgError>
pub fn save(&self, site_dir: &Path) -> Result<(), SsgError>
Persists the cache to site_dir/.ssg-plugin-cache.json.
§Examples
use ssg::plugin::PluginCache;
use tempfile::tempdir;
let dir = tempdir().unwrap();
PluginCache::new().save(dir.path()).unwrap();
assert!(dir.path().join(".ssg-plugin-cache.json").exists());Sourcepub fn has_changed(&self, path: &Path) -> bool
pub fn has_changed(&self, path: &Path) -> bool
Returns true if the file at path has changed since the last
time it was recorded, or if it has never been recorded.
§Examples
use ssg::plugin::PluginCache;
use tempfile::tempdir;
use std::fs;
let dir = tempdir().unwrap();
let f = dir.path().join("x.txt");
fs::write(&f, "a").unwrap();
let mut c = PluginCache::new();
// Never recorded ⇒ has_changed = true.
assert!(c.has_changed(&f));
c.update(&f);
assert!(!c.has_changed(&f));Sourcepub fn update(&mut self, path: &Path)
pub fn update(&mut self, path: &Path)
Records the current content hash for path.
§Examples
use ssg::plugin::PluginCache;
use tempfile::tempdir;
use std::fs;
let dir = tempdir().unwrap();
let f = dir.path().join("x.txt");
fs::write(&f, "hi").unwrap();
let mut c = PluginCache::new();
c.update(&f);
assert!(!c.has_changed(&f));Trait Implementations§
Source§impl Clone for PluginCache
impl Clone for PluginCache
Source§fn clone(&self) -> PluginCache
fn clone(&self) -> PluginCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PluginCache
impl Debug for PluginCache
Source§impl Default for PluginCache
impl Default for PluginCache
Source§fn default() -> PluginCache
fn default() -> PluginCache
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PluginCache
impl RefUnwindSafe for PluginCache
impl Send for PluginCache
impl Sync for PluginCache
impl Unpin for PluginCache
impl UnsafeUnpin for PluginCache
impl UnwindSafe for PluginCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more