twilight_model/guild/invite/
channel.rs

1use crate::{
2    channel::ChannelType,
3    id::{marker::ChannelMarker, Id},
4};
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
8pub struct InviteChannel {
9    /// ID of the channel.
10    pub id: Id<ChannelMarker>,
11    /// Name of the channel.
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub name: Option<String>,
14    /// Type of the channel.
15    #[serde(rename = "type")]
16    pub kind: ChannelType,
17}
18
19#[cfg(test)]
20mod tests {
21    use super::{ChannelType, InviteChannel};
22    use crate::id::Id;
23    use serde_test::Token;
24
25    #[test]
26    fn invite_channel() {
27        let value = InviteChannel {
28            id: Id::new(1),
29            name: Some("channel name".to_owned()),
30            kind: ChannelType::GuildText,
31        };
32
33        serde_test::assert_tokens(
34            &value,
35            &[
36                Token::Struct {
37                    name: "InviteChannel",
38                    len: 3,
39                },
40                Token::Str("id"),
41                Token::NewtypeStruct { name: "Id" },
42                Token::Str("1"),
43                Token::Str("name"),
44                Token::Some,
45                Token::Str("channel name"),
46                Token::Str("type"),
47                Token::U8(0),
48                Token::StructEnd,
49            ],
50        )
51    }
52}