Skip to main content

intrepid_model/caches/
cache.rs

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