summaryrefslogtreecommitdiffstats
path: root/graphics/src/cached.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-22 01:53:48 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-22 01:53:48 +0100
commit85800c99ab285efd244c0addfdcf3c732a98de1d (patch)
tree7e8c785019ad0cf9729803c20a763976e605efff /graphics/src/cached.rs
parent53a183fe0d6aed460fbb8155ac9541757277aab3 (diff)
downloadiced-85800c99ab285efd244c0addfdcf3c732a98de1d.tar.gz
iced-85800c99ab285efd244c0addfdcf3c732a98de1d.tar.bz2
iced-85800c99ab285efd244c0addfdcf3c732a98de1d.zip
Fix broken links in documentation
Diffstat (limited to 'graphics/src/cached.rs')
-rw-r--r--graphics/src/cached.rs33
1 files changed, 33 insertions, 0 deletions
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<T> Cached for Primitive<T> {
+ type Cache = Arc<Self>;
+
+ fn load(cache: &Arc<Self>) -> Self {
+ Self::Cache {
+ content: cache.clone(),
+ }
+ }
+
+ fn cache(self) -> Arc<Self> {
+ Arc::new(self)
+ }
+}