pub struct CacheCodec { /* private fields */ }Expand description
Type-erased codec for serializing and deserializing cache entries.
CacheCodec is two plain function pointers — it is Copy and has no
heap allocation. Construct one via CacheCodec::from_impl for types
that implement CacheCodecImpl, or CacheCodec::new for custom
cases (e.g. when the orphan rule prevents a direct impl).
Implementations§
Source§impl CacheCodec
impl CacheCodec
Sourcepub fn new(
serialize: fn(&Arc<dyn Any + Send + Sync>, &mut dyn Write) -> Result<()>,
deserialize: fn(&Bytes) -> Result<Arc<dyn Any + Send + Sync>>,
) -> Self
pub fn new( serialize: fn(&Arc<dyn Any + Send + Sync>, &mut dyn Write) -> Result<()>, deserialize: fn(&Bytes) -> Result<Arc<dyn Any + Send + Sync>>, ) -> Self
Create a CacheCodec from plain function pointers.
Prefer from_impl when the value type implements
CacheCodecImpl. Use this for types where a direct impl isn’t
possible (e.g. orphan rule prevents it).
Sourcepub fn from_impl<T: CacheCodecImpl + 'static>() -> Self
pub fn from_impl<T: CacheCodecImpl + 'static>() -> Self
Create a CacheCodec from a CacheCodecImpl implementation.
For sized types stored directly in the cache. The codec
downcasts &dyn Any to &T for serialization and returns Arc<T>
from deserialization.
pub fn serialize( &self, value: &Arc<dyn Any + Send + Sync>, writer: &mut dyn Write, ) -> Result<()>
pub fn deserialize(&self, data: &Bytes) -> Result<Arc<dyn Any + Send + Sync>>
Trait Implementations§
Source§impl Clone for CacheCodec
impl Clone for CacheCodec
Source§fn clone(&self) -> CacheCodec
fn clone(&self) -> CacheCodec
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CacheCodec
impl Debug for CacheCodec
impl Copy for CacheCodec
Auto Trait Implementations§
impl Freeze for CacheCodec
impl RefUnwindSafe for CacheCodec
impl Send for CacheCodec
impl Sync for CacheCodec
impl Unpin for CacheCodec
impl UnsafeUnpin for CacheCodec
impl UnwindSafe for CacheCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more