| Crates.io | stream-ws |
| lib.rs | stream-ws |
| version | 0.1.1 |
| created_at | 2023-10-12 10:35:47.05335+00 |
| updated_at | 2023-10-12 14:43:29.880646+00 |
| description | A layer over WebSocket enables carrying byte stream, for both native and WebAssembly. |
| homepage | https://github.com/idkidknow/stream-ws |
| repository | https://github.com/idkidknow/stream-ws |
| max_upload_size | |
| id | 1001190 |
| size | 66,756 |
A layer over WebSocket enables carrying byte stream, for both native and WebAssembly.
Providing methods able to wrap any WebSocket message stream implementation,
and impl AsyncRead,
AsyncBufRead
and AsyncWrite.
run cargo add stream-ws to bring it into your crate.
Examples in examples/.
With feature tungstenite.
For WebSocketStream in either crate tokio-tungstenite
or async-tungstenite,
use
let stream = stream_ws::tungstenite::WsByteStream::new(inner)
With feature gloo.
For WebSocket
in crate gloo
use
let stream = stream_ws::gloo::WsByteStream::new(inner)
Your WebSocket implementation should have a struct S satisfying trait bound
Stream<Item = Result<Msg, E>> + Sink<Msg, Error = E> + Unpin
where Msg and E
are message and error type of the implementation.
Create a struct Handler and impl
WsMessageHandle,
which is easy, and then
call Handler::wrap_stream(underlying_stream)
to get a WsByteStream.
tokio: impl tokio's AsyncRead, AsyncBufRead and AsyncWrite variantstungstenite: handlers for message and error type from crate tungstenitegloo: handlers for message and error type from crate glooLicense: MIT OR Apache-2.0