websocket_lite/lib.rs
1#![warn(missing_docs)]
2#![warn(rust_2018_idioms)]
3#![cfg_attr(feature = "nightly", feature(test))]
4
5//! A fast, low-overhead WebSocket client.
6//!
7//! This crate is optimised for receiving a high volume of messages over a long period. A key feature is that it makes
8//! no memory allocations once the connection is set up and the initial messages have been sent and received; it reuses
9//! a single pair of buffers, which are sized for the longest message seen so far.
10//!
11//! You can use this crate in both asynchronous (futures-based) and synchronous code.
12//! `native_tls` provides the TLS functionality for `wss://...` servers.
13//!
14//! This crate is fully conformant with the fuzzingserver module in the
15//! [Autobahn test suite](https://github.com/crossbario/autobahn-testsuite).
16
17mod client;
18mod ssl;
19mod sync;
20
21pub use crate::client::ClientBuilder;
22
23pub use websocket_codec::{Error, Message, MessageCodec, Opcode, Result};
24
25use std::io::{Read, Write};
26
27use tokio::io::{AsyncRead, AsyncWrite};
28use tokio_util::codec::Framed;
29
30/// Used by [`AsyncClient`](type.AsyncClient.html) to represent types that are `AsyncRead` and `AsyncWrite`.
31pub trait AsyncNetworkStream: AsyncRead + AsyncWrite {}
32
33impl<S> AsyncNetworkStream for S where S: AsyncRead + AsyncWrite {}
34
35/// Used by [`Client`](type.Client.html) to represent types that are `Read` and `Write`.
36pub trait NetworkStream: Read + Write {}
37
38impl<S> NetworkStream for S where S: Read + Write {}
39
40/// Exposes a `Sink` and a `Stream` for sending and receiving WebSocket messages asynchronously.
41pub type AsyncClient<S> = Framed<S, MessageCodec>;
42
43/// Sends and receives WebSocket messages synchronously.
44pub type Client<S> = sync::Framed<S, MessageCodec>;