pub trait Codec<T>:
Send
+ Sync
+ 'static {
// Required methods
fn encode<'a>(
&'a self,
value: &'a T,
) -> BoxFuture<'a, Result<Payload, BoxError>>;
fn decode(&self, payload: Payload) -> BoxFuture<'_, Result<T, BoxError>>;
// Provided method
fn encode_owned(
&self,
value: Arc<T>,
) -> BoxFuture<'_, Result<Payload, BoxError>>
where T: Send + Sync + 'static { ... }
}Expand description
Encodes cached values to payloads and decodes them back.
Encoding and decoding are asynchronous so a codec may await. For ordinary
synchronous serializers implement SyncCodec and wrap the codec in
FromSync. Every decode must return an independent value: the cache may
retain one payload and decode it more than once.
Required Methods§
Provided Methods§
Sourcefn encode_owned(
&self,
value: Arc<T>,
) -> BoxFuture<'_, Result<Payload, BoxError>>
fn encode_owned( &self, value: Arc<T>, ) -> BoxFuture<'_, Result<Payload, BoxError>>
Serialize a shared value owned by the cache.
The engine calls this method for remote writes. By default it delegates
to encode without copying the value. Override it to
move the shared handle into a background job without requiring T: Clone.
The codec owns scheduling, admission and the lifetime of any jobs it
starts; those jobs do not inherit the cache’s shadow-capacity token.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".