pub struct CodecRegistry { /* private fields */ }Expand description
Process-wide registry of codecs, keyed by codec id.
Implementations§
Source§impl CodecRegistry
impl CodecRegistry
Sourcepub fn register(&mut self, codec: Box<dyn Codec>)
pub fn register(&mut self, codec: Box<dyn Codec>)
Register a codec. Id collisions are rejected at runtime — two codecs claiming the same id is a programming error, not a recoverable condition.
§Panics
Panics if a codec with the same id is already registered.
Sourcepub fn compress(&self, id: u8, plaintext: &[u8]) -> Result<Vec<u8>, CoreError>
pub fn compress(&self, id: u8, plaintext: &[u8]) -> Result<Vec<u8>, CoreError>
Dispatch compression to the codec identified by id.
§Errors
Returns CoreError::UnsupportedFeature if no codec with id is
registered.
Sourcepub fn decompress(
&self,
id: u8,
compressed: &[u8],
expected_len: u32,
) -> Result<Vec<u8>, CoreError>
pub fn decompress( &self, id: u8, compressed: &[u8], expected_len: u32, ) -> Result<Vec<u8>, CoreError>
Dispatch decompression to the codec identified by id.
§Errors
Returns CoreError::UnsupportedFeature if no codec with id is
registered, or CoreError::Corrupt if decompression fails.
Sourcepub fn compress_with_tunables(
&self,
id: u8,
plaintext: &[u8],
tunables: &CodecTunables,
) -> Result<Vec<u8>, CoreError>
pub fn compress_with_tunables( &self, id: u8, plaintext: &[u8], tunables: &CodecTunables, ) -> Result<Vec<u8>, CoreError>
Dispatch compression with a tunables hint. Codecs that don’t
override the trait method fall through to plain compress.
§Errors
Same as CodecRegistry::compress.
Source§impl CodecRegistry
impl CodecRegistry
Sourcepub fn codec_name(&self, codec_id: u8) -> Option<&'static str>
pub fn codec_name(&self, codec_id: u8) -> Option<&'static str>
Human-readable name for a registered codec id.
Trait Implementations§
Source§impl Debug for CodecRegistry
impl Debug for CodecRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for CodecRegistry
impl !UnwindSafe for CodecRegistry
impl Freeze for CodecRegistry
impl Send for CodecRegistry
impl Sync for CodecRegistry
impl Unpin for CodecRegistry
impl UnsafeUnpin for CodecRegistry
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> 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