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:

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

The type produced by join
The type produced by part
The type produced by ping
The type produced by pong
The type produced by privmsg or reply
The type produced by raw
The type produced by register

Enums

Request a capability from Twitch

Constants

Traits

A trait for encoding a message with std::io::Write
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