pub trait WebSocket: Stream<Item = Result<Message, Error>> + Sink<Message, Error = Error> { }Expand description
An open WebSocket: messages out, messages in.
Stream for the receiving half and Sink for the sending half, on one
value rather than a split pair, because splitting is something
futures_util::StreamExt::split already does for any Stream + Sink
and a seam that pre-split would take that choice away from the caller.
§The error type is concrete, unlike Transport::Error
Transport carries type Error and a to_error
hook so a backend whose error is genuinely !Send can still implement
it. That escape hatch has no subject here: it exists so a backend can
keep its own typed source while Client classifies, and there is no
Client between this trait and its caller — whatever a backend would
put in its own error, it can put in Error’s source, which is where
a caller would read it from anyway. One concrete type also keeps
Stream::Item’s error and Sink::Error the same type without an
associated-type equality the caller has to spell out.
§Ending
The Stream ends (None) when the connection is finished: after the
peer’s Message::Close has been delivered, or when the connection
broke and the error has already been reported. A Stream that has
ended stays ended.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".