From 85800c99ab285efd244c0addfdcf3c732a98de1d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 01:53:48 +0100 Subject: Fix broken links in documentation --- graphics/src/cached.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 graphics/src/cached.rs (limited to 'graphics/src/cached.rs') diff --git a/graphics/src/cached.rs b/graphics/src/cached.rs new file mode 100644 index 00000000..f7968c9f --- /dev/null +++ b/graphics/src/cached.rs @@ -0,0 +1,33 @@ +use crate::Primitive; + +use std::sync::Arc; + +/// A piece of data that can be cached. +pub trait Cached: Sized { + /// The type of cache produced. + type Cache; + + /// 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) -> Self::Cache; +} + +impl Cached for Primitive { + type Cache = Arc; + + fn load(cache: &Arc) -> Self { + Self::Cache { + content: cache.clone(), + } + } + + fn cache(self) -> Arc { + Arc::new(self) + } +} -- cgit