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§
fn encode(&self) -> Result<WsMessage, EncodeError>
fn decode(msg: WsMessage) -> Result<Self, DecodeError>
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§
impl WsCodec for NoMessages
impl<T: Serialize + DeserializeOwned> WsCodec for T
Blanket impl: JSON text encoding for any serde type.