1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! # Encoding utilies
//!
//! ## Using the [Encodable](crate::Encodable) trait
//! Many [commands](crate::commands) are provided that can be encoded to a writer.
//!
//! ```
//! use twitchchat::{Encodable, commands};
//! // or anything that impls `std::io::Write`
//! let mut buf = vec![];
//! // the commands produce 0-copy types
//! let join_cmd = commands::join("museun");
//!
//! // which implement encode, which lets them to be written to a std:::Write
//! join_cmd.encode(&mut buf).unwrap();
//!
//! // join, for example, makes sure '#' is included in the channel name.
//! let string = std::str::from_utf8(&buf).unwrap();
//! assert_eq!(string, "JOIN #museun\r\n");
//! ```
//!
//! ## Using an Encoder
//! This crate provides composable types (Writers/Encoders) which can be used with the [Encodable](crate::Encodable) trait.
//! The types come in both `Sync` and `Async` styles.
//!
//! ```
//! use twitchchat::commands;
//!
//! let mut buf = vec![];
//! let mut enc = twitchchat::Encoder::new(&mut buf);
//! enc.encode(commands::join("museun")).unwrap();
//!
//! use std::io::Write as _;
//! enc.write_all(b"its also a writer\r\n").unwrap();
//! enc.flush().unwrap();
//!
//! let string = std::str::from_utf8(&buf).unwrap();
//! assert_eq!(string, "JOIN #museun\r\nits also a writer\r\n");
//! ```
cfg_async!
pub use *;