iced-yoda/graphics/src/cached.rs

25 lines
619 B
Rust
Raw Normal View History

2024-03-22 01:53:48 +01:00
/// A piece of data that can be cached.
pub trait Cached: Sized {
/// The type of cache produced.
type Cache: Clone;
2024-03-22 01:53:48 +01:00
/// Loads the [`Cache`] into a proper instance.
///
/// [`Cache`]: Self::Cache
fn load(cache: &Self::Cache) -> Self;
/// Caches this value, producing its corresponding [`Cache`].
///
/// [`Cache`]: Self::Cache
fn cache(self, previous: Option<Self::Cache>) -> Self::Cache;
2024-03-22 01:53:48 +01:00
}
#[cfg(debug_assertions)]
impl Cached for () {
type Cache = ();
fn load(_cache: &Self::Cache) -> Self {}
fn cache(self, _previous: Option<Self::Cache>) -> Self::Cache {}
}