Module twitch_message::encode
source · Expand description
This module provides encoding of typed messages
Without the std
feature enabled, you’ll only be able to encode to a core::fmt::Write
source (e.g. a String
)
If you enable the std
feature, then you’ll also be able to encode to a std::io::Write
source (e.g. a Vec<u8>
or a std::net::TcpStream
)
Provided traits:
Trait | Description | Feature | Example |
---|---|---|---|
Format | Format this message to the core::fmt::Write | – | ping("asdf").format(&mut buf) |
Formattable | Using core::fmt::Write format this message | – | buf.format_msg(ping("asdf")) |
Encode | Encode this message to the std::io::Write | std | ping("asdf").encode(&mut buf) |
Encodable | Using std::io::Write type encode this message | std | buf.encode_msg(ping("asdf")) |
Using one of the functions creates one of the types.
These don’t allocate directly and when using with &'static str
can be stored in static
/const
contexts.
Example
use twitch_message::encode::{privmsg, Privmsg, Format, Formattable};
const KAPPA: Privmsg<'static> = privmsg("museun", "Kappa");
let vohiyo = privmsg("museun", "VoHiYo");
let mut buf = String::new();
KAPPA.format(&mut buf)?;
buf.format_msg(vohiyo)?;
assert_eq!(buf, "PRIVMSG #museun :Kappa\r\nPRIVMSG #museun :VoHiYo\r\n");
Structs
Enums
Request a capability from Twitch
Constants
All of the
Capabilities
Traits
Encodable
std
A trait for encoding a message with
std::io::Write
Encode
std
A trait to encode a type onto this
std::io::Write
A trait to format a type onto this
core::fmt::Write
A trait for formatting a message with
core::fmt::Write
Functions
Join a channel
Leave a channel
Constructs a PING the server should reply to
Construct a PONG message, these are used to respond to a Ping
Sends a message to a channel
Send a raw message to the server
This allows you to initialize the registration handshake with the server
Sends a message to a channel, with a provided
reply-parent-msg-id
attached