twilight_model/channel/message/component/
separator.rs

1use serde::{Deserialize, Serialize};
2
3/// A separator is a layout component that adds vertical padding and
4/// visual division between components.
5#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
6pub struct Separator {
7    /// Optional identifier for the separator.
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub id: Option<i32>,
10    /// Whether a visual divider should be shown. Defaults to `true`.
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub divider: Option<bool>,
13    /// The size of the separator padding. Defaults to `Small`.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub spacing: Option<SeparatorSpacingSize>,
16}
17
18/// The size of the separator padding.
19#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
20#[serde(from = "u8", into = "u8")]
21pub enum SeparatorSpacingSize {
22    /// A small separator padding.
23    Small,
24    /// A large separator padding.
25    Large,
26    /// An arbitrary separator padding.
27    Other(u8),
28}
29
30impl From<u8> for SeparatorSpacingSize {
31    fn from(value: u8) -> Self {
32        match value {
33            1 => SeparatorSpacingSize::Small,
34            2 => SeparatorSpacingSize::Large,
35            other => SeparatorSpacingSize::Other(other),
36        }
37    }
38}
39
40impl From<SeparatorSpacingSize> for u8 {
41    fn from(value: SeparatorSpacingSize) -> Self {
42        match value {
43            SeparatorSpacingSize::Small => 1,
44            SeparatorSpacingSize::Large => 2,
45            SeparatorSpacingSize::Other(other) => other,
46        }
47    }
48}