2023-02-15 17:40:24 -05:00
|
|
|
/// Trait for objects that are cacheable.
|
2023-02-12 22:36:50 -05:00
|
|
|
pub trait Cacheable {
|
|
|
|
fn from_bytes(bytes: &[u8]) -> Option<Self>
|
|
|
|
where
|
|
|
|
Self: Sized;
|
|
|
|
|
|
|
|
fn to_bytes(&self) -> Option<Vec<u8>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Cacheable for Vec<u8> {
|
|
|
|
fn from_bytes(bytes: &[u8]) -> Option<Self> {
|
|
|
|
Some(Vec::from(bytes))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_bytes(&self) -> Option<Vec<u8>> {
|
|
|
|
Some(self.to_vec())
|
|
|
|
}
|
|
|
|
}
|