pub struct Rich {
pub v: u32,
pub blocks: Vec<Block>,
}Expand description
A rich payload: the object stored under the content key
({"v":1,"blocks":[...]}).
Fields§
§v: u32Payload version (RICH_VERSION).
blocks: Vec<Block>The blocks, drawn in order under the message.
Implementations§
Source§impl Rich
impl Rich
Sourcepub fn math_only(&self) -> Option<Math>
pub fn math_only(&self) -> Option<Math>
The math of a payload whose only block is a math block: such a
message is sent as an m.image (the PNG render) when it has no
separate text. None for anything else.
Sourcepub fn find_math(&self) -> Option<(&str, bool)>
pub fn find_math(&self) -> Option<(&str, bool)>
The first math block’s TeX and whether it is display math (the
default), in any payload (unlike Rich::math_only).
One buttons block.
Sourcepub fn parse(json: &str) -> Result<Self, String>
pub fn parse(json: &str) -> Result<Self, String>
Parses a payload, turns its floats into decimal strings
(Rich::canonicalize) and validates it.
Sourcepub fn canonicalize(&mut self) -> Result<(), String>
pub fn canonicalize(&mut self) -> Result<(), String>
Makes the payload canonical JSON, which event content must be: every
float becomes an integer (no fraction) or its shortest decimal string
(62.99 → "62.99"). Senders call this before Rich::validate, so
callers that write floats keep working. Integers outside
±MAX_SAFE_INT are an error.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Whether this version can send it: known v, 1..=MAX_BLOCKS
blocks of known types, 1..=MAX_BUTTONS buttons (or
1..=MAX_CHIPS chips) per action block with labels of
1..=MAX_LABEL characters, non-empty react keys and send bodies,
display blocks with their required fields, and the size caps.
Sourcepub fn form_fallback(&self) -> Option<String>
pub fn form_fallback(&self) -> Option<String>
A plain-text body for the payload’s forms (form_fallback), or
None without forms: a sender’s default text when it has none.
Sourcepub fn react_keys(&self) -> Vec<String>
pub fn react_keys(&self) -> Vec<String>
The keys of every react action (buttons, chips, card actions), in
order, without duplicates.