# WTX
[](https://github.com/c410-f3r/wtx/actions?query=workflow%3ACI)
[](https://crates.io/crates/wtx)
[](https://docs.rs/wtx)
[](./LICENSE)
[](https://blog.rust-lang.org/2020/03/12/Rust-1.71.html)
Intended to group different web transport implementations.
## WebSocket
Provides low and high level abstractions to dispatch frames, as such, it is up to you to implement [Stream](https://docs.rs/wtx/latest/wtx/trait.Stream.html) with any desired logic or use any of the built-in strategies through the selection of features.
[fastwebsockets](https://github.com/denoland/fastwebsockets) served as an initial inspiration for the skeleton of this implementation so thanks to the authors.
```rust
use wtx::{Stream, web_socket::{FrameMutVec, FrameVecMut, OpCode, WebSocketClientOwned}};
pub async fn handle_client_frames(ws: &mut WebSocketClientOwned<impl Stream>) -> wtx::Result<()> {
let fb = &mut <_>::default();
loop {
let frame = match ws.read_msg(fb).await {
Err(err) => {
println!("Error: {err}");
ws.write_frame(&mut FrameMutVec::new_fin(fb, OpCode::Close, &[])?).await?;
break;
}
Ok(elem) => elem,
};
match (frame.op_code(), frame.text_payload()) {
(_, Some(elem)) => println!("{elem}"),
(OpCode::Close, _) => break,
_ => {}
}
}
Ok(())
}
```
See the `examples` directory for more suggestions.