pub struct Cache { /* private fields */ }Expand description
Persistent store of previously seen flake URIs.
Powers shell-completion suggestions, ranked by hit count.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn commit(&self) -> Result<()>
pub fn commit(&self) -> Result<()>
Write the cache to its on-disk location, creating the parent directory if needed.
Sourcepub fn load() -> Self
pub fn load() -> Self
Load the cache from the default location, or return an empty cache on any failure.
Sourcepub fn from_path(path: &Path) -> Self
pub fn from_path(path: &Path) -> Self
Load the cache from path, or return an empty cache on any failure.
Sourcepub fn try_from_path(path: &Path) -> Result<Self>
pub fn try_from_path(path: &Path) -> Result<Self>
Load the cache from path, surfacing read or parse errors.
§Errors
Returns std::io::Error if path cannot be opened or its JSON
payload cannot be deserialized.
Sourcepub fn add_entry(&mut self, id: String, uri: String)
pub fn add_entry(&mut self, id: String, uri: String)
Insert or bump the hit count of the (id, uri) entry.
Sourcepub fn list_uris_for_id(&self, id: &str) -> Vec<String>
pub fn list_uris_for_id(&self, id: &str) -> Vec<String>
Cached URIs for id sorted by descending hit count.
Useful for the change workflow, which suggests URIs that have been
used for the same input id (e.g. both a remote github: and a local
path: URI for testing).
Sourcepub fn populate_from_inputs<'a>(
&mut self,
inputs: impl Iterator<Item = (&'a str, &'a str)>,
)
pub fn populate_from_inputs<'a>( &mut self, inputs: impl Iterator<Item = (&'a str, &'a str)>, )
Insert any (id, uri) pairs not already present, without bumping hit
counts on existing entries.
Use this when populating the cache as a side effect of any command
that reads inputs (list, change, update, …), not only add.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cache
impl<'de> Deserialize<'de> for Cache
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>,
Auto Trait Implementations§
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
impl UnwindSafe for Cache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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>
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