Trait asset_lru::Decoder[][src]

pub trait Decoder {
    type Output: Send + Sync;
    type Error: Error;
    fn decode<R: Read + Seek>(
        &self,
        reader: R
    ) -> Result<Self::Output, Self::Error>;
fn estimate_cost(&self, item: &Self::Output) -> Result<u64, Self::Error>; fn decode_bytes(&self, bytes: &[u8]) -> Result<Self::Output, Self::Error> { ... } }
Expand description

A Decoder knows how to get from a reader to a decoded representation in memory.

The output type must be sync in order to enable the cache to store elements behind Arc.

This crate does not insert a std::io::BufReader for you. You should do so yourself as needed.

Associated Types

Required methods

Estimate the cost of a decoded item, usually the in-memory size.

Provided methods

Sometimes it is possible for the cache to directly provide bytes. Implement this optional method to take advantage of that case.

By default this just forwards to the read function. Useful because some decoders are faster if they can be fed a slice of bytes, for example serde_json.

Implementors