Codec

Trait Codec 

Source
pub trait Codec: Default {
    type Encode: Send + 'static;
    type Decode: Send + 'static;
    type Encoder: Encoder<Item = Self::Encode>;
    type Decoder: Decoder<Item = Self::Decode>;

    const CONTENT_TYPES: &'static [&'static str];

    // Required methods
    fn encoder(&mut self) -> Self::Encoder;
    fn decoder(&mut self) -> Self::Decoder;

    // Provided method
    fn check_content_type(&self, ct: &str) -> bool { ... }
}
Expand description

Represents a type that can encode/decode a message

Required Associated Constants§

Source

const CONTENT_TYPES: &'static [&'static str]

Content types

Required Associated Types§

Source

type Encode: Send + 'static

The encodable message

Source

type Decode: Send + 'static

The decodable message

Source

type Encoder: Encoder<Item = Self::Encode>

The encoder that can encode a message

Source

type Decoder: Decoder<Item = Self::Decode>

The decoder that can encode a message

Required Methods§

Source

fn encoder(&mut self) -> Self::Encoder

Create the encoder

Source

fn decoder(&mut self) -> Self::Decoder

Create the decoder

Provided Methods§

Source

fn check_content_type(&self, ct: &str) -> bool

Returns whether the specified content type is supported

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, U> Codec for JsonCodec<T, U>
where T: Serialize + Send + 'static, U: DeserializeOwned + Send + 'static,

Available on crate feature json-codec only.
Source§

const CONTENT_TYPES: &'static [&'static str]

Source§

type Encode = T

Source§

type Decode = U

Source§

type Encoder = JsonEncoder<T>

Source§

type Decoder = JsonDecoder<U>

Source§

impl<T, U> Codec for JsonI64ToStringCodec<T, U>
where T: Serialize + Send + 'static, U: DeserializeOwned + Send + 'static,

Available on crate feature json-codec only.
Source§

const CONTENT_TYPES: &'static [&'static str]

Source§

type Encode = T

Source§

type Decode = U

Source§

type Encoder = JsonI64ToStringEncoder<T>

Source§

type Decoder = JsonI64ToStringDecoder<U>

Source§

impl<T, U> Codec for ProstCodec<T, U>
where T: Message + Send + 'static, U: Message + Default + Send + 'static,

Source§

const CONTENT_TYPES: &'static [&'static str]

Source§

type Encode = T

Source§

type Decode = U

Source§

type Encoder = ProstEncoder<T>

Source§

type Decoder = ProstDecoder<U>