Module 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:

TraitDescriptionFeatureExample
FormatFormat this message to the core::fmt::Writeping("asdf").format(&mut buf)
FormattableUsing core::fmt::Write format this messagebuf.format_msg(ping("asdf"))
EncodeEncode this message to the std::io::Writestdping("asdf").encode(&mut buf)
EncodableUsing std::io::Write type encode this messagestdbuf.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§

Join
The type produced by join
Part
The type produced by part
Ping
The type produced by ping
Pong
The type produced by pong
Privmsg
The type produced by privmsg or reply
Raw
The type produced by raw
Register
The type produced by register

Enums§

Capability
Request a capability from Twitch

Constants§

ALL_CAPABILITIES
All of the Capabilities

Traits§

Encodablestd
A trait for encoding a message with std::io::Write
Encodestd
A trait to encode a type onto this std::io::Write
Format
A trait to format a type onto this core::fmt::Write
Formattable
A trait for formatting a message with core::fmt::Write

Functions§

join
Join a channel
part
Leave a channel
ping
Constructs a PING the server should reply to
pong
Construct a PONG message, these are used to respond to a Ping
privmsg
Sends a message to a channel
raw
Send a raw message to the server
register
This allows you to initialize the registration handshake with the server
reply
Sends a message to a channel, with a provided reply-parent-msg-id attached