pub struct CodecRegistry { /* private fields */ }Expand description
Central registry of compression/encoding codecs.
On construction the seven built-in codecs are pre-registered. Custom codecs
can be added via CodecRegistry::register; duplicate ids are rejected.
Implementations§
Source§impl CodecRegistry
impl CodecRegistry
Sourcepub fn register(
&mut self,
descriptor: CodecDescriptor,
) -> Result<(), CodecError>
pub fn register( &mut self, descriptor: CodecDescriptor, ) -> Result<(), CodecError>
Register a custom CodecDescriptor.
Returns CodecError::AlreadyRegistered if a codec with the same id
already exists in the registry.
Sourcepub fn get(&self, id: CodecId) -> Option<&CodecDescriptor>
pub fn get(&self, id: CodecId) -> Option<&CodecDescriptor>
Look up a codec by its id.
Returns None when the id is not registered.
Sourcepub fn list_all(&self) -> Vec<&CodecDescriptor>
pub fn list_all(&self) -> Vec<&CodecDescriptor>
Return all registered codecs, sorted in ascending CodecId order.
Sourcepub fn negotiate(local: &[CodecId], remote: &[CodecId]) -> Option<CodecId>
pub fn negotiate(local: &[CodecId], remote: &[CodecId]) -> Option<CodecId>
Negotiate a codec between two peers.
Returns the first id in local that also appears in remote, or None
if there is no common codec. This is a static method because negotiation
does not require access to a registry instance — it operates purely on
the id sets.
Sourcepub fn best_for_speed(&self) -> Option<&CodecDescriptor>
pub fn best_for_speed(&self) -> Option<&CodecDescriptor>
Return a reference to the fastest registered codec.
When multiple codecs share the best speed class the one with the
numerically smallest CodecId is returned for determinism.
Returns None only if the registry is empty (not possible after
new() unless all entries were somehow replaced).
Sourcepub fn best_for_compression(&self) -> Option<&CodecDescriptor>
pub fn best_for_compression(&self) -> Option<&CodecDescriptor>
Return a reference to the codec with the lowest
compression_ratio_estimate (best compression).
When multiple codecs share the same ratio the one with the numerically
smallest CodecId is returned for determinism. NaN ratio values are
sorted last.
Returns None only if the registry is empty.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CodecRegistry
impl RefUnwindSafe for CodecRegistry
impl Send for CodecRegistry
impl Sync for CodecRegistry
impl Unpin for CodecRegistry
impl UnsafeUnpin for CodecRegistry
impl UnwindSafe for CodecRegistry
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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>
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