Skip to main content

WsCodec

Trait WsCodec 

Source
pub trait WsCodec: Sized {
    // Required methods
    fn encode(&self) -> Result<WsMessage, EncodeError>;
    fn decode(msg: WsMessage) -> Result<Self, DecodeError>;
}
Expand description

Encode/decode messages to/from WebSocket frames.

A blanket implementation covers anything that implements Serialize + DeserializeOwned, encoding as JSON text frames. Implement manually for binary protocols.

Required Methods§

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 WsCodec for NoMessages

Source§

impl<T: Serialize + DeserializeOwned> WsCodec for T

Blanket impl: JSON text encoding for any serde type.