autocache 0.2.1

automatic cache management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use bytes::Buf;

pub trait Codec: serde::Serialize + serde::de::DeserializeOwned {
    fn decode(data: bytes::Bytes) -> anyhow::Result<Self> {
        Ok(serde_json::from_reader(data.reader())?)
    }

    fn encode(&self) -> anyhow::Result<bytes::Bytes> {
        Ok(serde_json::to_vec(&self)?.into())
    }

    fn name() -> &'static str {
        "json"
    }
}