moka/common/
error.rs

1use std::{error::Error, fmt::Display};
2
3/// The error type for the functionalities around
4/// [`Cache::invalidate_entries_if`][invalidate-if] method.
5///
6/// [invalidate-if]: ./sync/struct.Cache.html#method.invalidate_entries_if
7#[derive(Debug)]
8pub enum PredicateError {
9    /// This cache does not have a necessary configuration enabled to support
10    /// invalidating entries with a closure.
11    ///
12    /// To enable the configuration, call
13    /// [`CacheBuilder::support_invalidation_closures`][support-invalidation-closures]
14    /// method at the cache creation time.
15    ///
16    /// [support-invalidation-closures]: ./sync/struct.CacheBuilder.html#method.support_invalidation_closures
17    InvalidationClosuresDisabled,
18}
19
20impl Display for PredicateError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(
23            f,
24            "Support for invalidation closures is disabled in this cache. \
25            Please enable it by calling the support_invalidation_closures \
26            method of the builder at the cache creation time",
27        )
28    }
29}
30
31impl Error for PredicateError {}