use crate::error::CacheError;
#[cfg(feature = "redis")]
pub mod l3_redis;
#[cfg(feature = "sled")]
pub mod l4_sled;
pub mod l5_origin;
#[cfg(feature = "redis")]
pub use l3_redis::L3RedisBackend;
#[cfg(feature = "sled")]
pub use l4_sled::L4SledBackend;
pub use l5_origin::{L5OriginBackend, OriginFetcher, OriginWriter};
#[cfg(feature = "oxigraph")]
pub mod l5_oxigraph;
#[cfg(feature = "oxigraph")]
pub use l5_oxigraph::L5OxigraphBackend;
pub trait ByteValue: Clone + Send + Sync + 'static {
fn encode_bytes(&self) -> Result<Vec<u8>, CacheError>;
fn decode_bytes(bytes: &[u8]) -> Result<Self, CacheError>;
}
impl ByteValue for Vec<u8> {
fn encode_bytes(&self) -> Result<Vec<u8>, CacheError> {
Ok(self.clone())
}
fn decode_bytes(bytes: &[u8]) -> Result<Self, CacheError> {
Ok(bytes.to_vec())
}
}
impl ByteValue for String {
fn encode_bytes(&self) -> Result<Vec<u8>, CacheError> {
Ok(self.as_bytes().to_vec())
}
fn decode_bytes(bytes: &[u8]) -> Result<Self, CacheError> {
String::from_utf8(bytes.to_vec()).map_err(|_| CacheError::SerializationFailed)
}
}