intrepid_model/caches/cache.rs
/// 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,
}
}
}