librashader_cache/
cacheable.rs

1/// Trait for objects that are cacheable.
2pub trait Cacheable {
3    fn from_bytes(bytes: &[u8]) -> Option<Self>
4    where
5        Self: Sized;
6
7    fn to_bytes(&self) -> Option<Vec<u8>>;
8}
9
10impl Cacheable for Vec<u8> {
11    fn from_bytes(bytes: &[u8]) -> Option<Self> {
12        Some(Vec::from(bytes))
13    }
14
15    fn to_bytes(&self) -> Option<Vec<u8>> {
16        Some(self.to_vec())
17    }
18}
19
20impl Cacheable for Option<Vec<u8>> {
21    fn from_bytes(bytes: &[u8]) -> Option<Self> {
22        Some(Some(Vec::from(bytes)))
23    }
24
25    fn to_bytes(&self) -> Option<Vec<u8>> {
26        self.clone()
27    }
28}