Skip to main content

QueryCache

Struct QueryCache 

Source
pub struct QueryCache<R> {
    path: Option<PathBuf>,
    entries: FxHashMap<String, QueryVal<R>>,
}

Fields§

§path: Option<PathBuf>

Where the cache is saved. None if caching is disabled.

§entries: FxHashMap<String, QueryVal<R>>

Implementations§

Source§

impl<R> QueryCache<R>

Source

pub fn new() -> Self

Source

pub fn insert(&mut self, key: String, constr_hash: u64, result: R)

Source

pub fn lookup(&self, key: &String, constr_hash: u64) -> Option<&R>

Source

pub fn lookup_by_key(&self, key: &str) -> Option<&R>

Look up a result by key only (no hash validation).

Source

pub fn update_result_by_key(&mut self, key: &str, f: impl FnOnce(&mut R))

Mutate a cached result by key only (no hash validation).

Source§

impl<R: Debug + Serialize + DeserializeOwned> QueryCache<R>

Source

pub fn save(&self) -> Result<(), Error>

Saves the cache to the file it was loaded from, overwriting it. Does nothing if the cache was not loaded from a file.

Source

pub fn load(path: PathBuf) -> Self

Loads the cache from path, starting with an empty cache if the file is missing or invalid. The cache is later saved to the same path.

Trait Implementations§

Source§

impl<R> Default for QueryCache<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> DynSend for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: DynSend,

§

impl<R> DynSync for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: DynSync,

§

impl<R> Freeze for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: Freeze,

§

impl<R> RefUnwindSafe for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: RefUnwindSafe,

§

impl<R> Send for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: Send,

§

impl<R> Sync for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: Sync,

§

impl<R> Unpin for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: Unpin,

§

impl<R> UnsafeUnpin for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: UnsafeUnpin,

§

impl<R> UnwindSafe for QueryCache<R>
where HashMap<String, QueryVal<R>, FxBuildHasher>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more