Skip to main content

Registry

Trait Registry 

Source
pub trait Registry:
    'static
    + Send
    + Sync {
    type Error: 'static + Send + Sync + Error;

    // Required method
    fn get_codec<'de, D: Deserializer<'de>>(
        &self,
        config: D,
    ) -> Result<ErasedDynCodec, Self::Error>;

    // Provided method
    fn get_codec_typed<'de, T: DynCodec, D: Deserializer<'de>>(
        &self,
        config: D,
    ) -> Result<Option<T>, Self::Error> { ... }
}
Expand description

Registry of codec types.

Required Associated Types§

Source

type Error: 'static + Send + Sync + Error

Error type that may be returned during get_codec.

Required Methods§

Source

fn get_codec<'de, D: Deserializer<'de>>( &self, config: D, ) -> Result<ErasedDynCodec, Self::Error>

Instantiate a codec of any type from its configuration.

The config must include the id field with the [DynCodecType::codec_id].

§Errors

Errors if no codec with a matching id has been registered, or if constructing the codec fails.

Provided Methods§

Source

fn get_codec_typed<'de, T: DynCodec, D: Deserializer<'de>>( &self, config: D, ) -> Result<Option<T>, Self::Error>

Instantiate a codec with a concrete type from its configuration.

Returns None if the constructed codec is of the wrong type.

The config must include the id field with the [DynCodecType::codec_id].

§Errors

Errors if no codec with a matching id has been registered, or if constructing the codec fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<R: Registry> Registry for Arc<R>

Source§

type Error = <R as Registry>::Error

Source§

fn get_codec<'de, D: Deserializer<'de>>( &self, config: D, ) -> Result<ErasedDynCodec, Self::Error>

Source§

fn get_codec_typed<'de, T: DynCodec, D: Deserializer<'de>>( &self, config: D, ) -> Result<Option<T>, Self::Error>

Source§

impl<R: Registry> Registry for Box<R>

Source§

type Error = <R as Registry>::Error

Source§

fn get_codec<'de, D: Deserializer<'de>>( &self, config: D, ) -> Result<ErasedDynCodec, Self::Error>

Source§

fn get_codec_typed<'de, T: DynCodec, D: Deserializer<'de>>( &self, config: D, ) -> Result<Option<T>, Self::Error>

Implementors§