intrepid_model/caches/
cache.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/// When dealing with caches, fetch values are the most common operation. This
/// enum represents the result of a fetch operation, and can be used to determine
/// if you've got a cache miss or not. It works a lot like the `Option` enum, but
/// with a bit more context.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum Cache<T> {
    /// The value was not found in the cache; cache miss.
    #[default]
    NotFound,
    /// The value was found in the cache; cache hit.
    Found(T),
}

impl<T> From<Option<T>> for Cache<T> {
    fn from(option: Option<T>) -> Self {
        match option {
            Some(value) => Cache::Found(value),
            None => Cache::NotFound,
        }
    }
}