Trait Codec

Source
pub trait Codec {
    type Error;

    // Required methods
    fn encode<S>(msg: S) -> Result<Vec<u8>, Self::Error>
       where S: Serialize;
    fn decode<R>(buf: Vec<u8>) -> Result<R, Self::Error>
       where R: DeserializeOwned;
}
Expand description

Trait for encoding and decoding WebSocket messages.

This allows you to customize how messages are encoded when sent over the wire.

Required Associated Types§

Source

type Error

The errors that can happen when using this codec.

Required Methods§

Source

fn encode<S>(msg: S) -> Result<Vec<u8>, Self::Error>
where S: Serialize,

Encode a message.

Source

fn decode<R>(buf: Vec<u8>) -> Result<R, Self::Error>

Decode a message.

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 Codec for JsonCodec

Available on crate feature json only.