websocket_base/ws/
mod.rs

1//! A module containing the traits and structs that lower layer of Rust-WebSocket is based on.
2//!
3//! This should not need to be used by regular users.
4//!
5//! Rust-WebSocket is based on three core traits: `Message`, `Sender` and `Receiver`. These
6//! traits have default implementations outside this module, however can be implemented
7//! by a user to extend the functionality provided.
8//!
9//! If a user wishes to use a different representation of a data frame, all three traits
10//! must be implemented by the user. If a user wishes to use a different representation
11//! of a message (but the same data frame), they must implement the `Message` and `Receiver`
12//! traits.
13//!
14//! A WebSocket message type must implement `Message<D>` where `D` is the type of data frame
15//! that the message can be converted to/from.
16//!
17//! When sending a message, the message is converted into an iterator with its `into_iter()`
18//! method, which allows the message to output data frames forming a fragmented message
19//! where each data frame is sent immediately to be reassembled at the remote endpoint.
20//!
21//! The type of data frame can be any type, however, if you choose a data frame type other than
22//! `DataFrame`, you will also have to implement the `Sender` and `Receiver` traits to
23//! send and receive data frames.
24//!
25//! A `Sender<D>` sends a data frame of type `D`, typically wrapping an underlying Writer,
26//! by implementing the `send_dataframe()` method. The `send_message()` method has a default
27//! implementation which turns the message into an iterator and then continually calls
28//! `send_dataframe()` with the frames from the iterator.
29//!
30//! To make life easier for a `Sender`, several utility functions are provided which write
31//! various pieces of data to a Writer. These are found within the `util` module.
32//!
33//! A Receiver<D> receives data frames of type D and messages of type Receiver::Message,
34//! typically wrapping an underlying Reader, by implementing the `recv_dataframe()` and
35//! `recv_message_dataframes()` methods. The `recv_message_dataframes()` method has to
36//! form a `Vec` of data frames which comprise one whole, single message.
37//!
38//! To make life easier for a `Receiver`, several utility functions are provided which read
39//! various pieces of data from a Reader. These are found within the `util` module.
40pub use self::message::Message;
41
42#[cfg(feature = "sync")]
43pub use self::receiver::Receiver;
44#[cfg(feature = "sync")]
45pub use self::receiver::{DataFrameIterator, MessageIterator};
46#[cfg(feature = "sync")]
47pub use self::sender::Sender;
48
49pub mod dataframe;
50pub mod message;
51pub mod util;
52
53#[cfg(feature = "sync")]
54pub mod receiver;
55#[cfg(feature = "sync")]
56pub mod sender;