twilight_model/gateway/presence/
client_status.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::gateway::presence::Status;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct ClientStatus {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub desktop: Option<Status>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mobile: Option<Status>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub web: Option<Status>,
}

#[cfg(test)]
mod tests {
    use super::{ClientStatus, Status};
    use serde_test::Token;

    #[test]
    fn mobile_online() {
        let value = ClientStatus {
            desktop: Some(Status::Idle),
            mobile: Some(Status::Online),
            web: Some(Status::DoNotDisturb),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "ClientStatus",
                    len: 3,
                },
                Token::Str("desktop"),
                Token::Some,
                Token::Enum { name: "Status" },
                Token::Str("idle"),
                Token::Unit,
                Token::Str("mobile"),
                Token::Some,
                Token::Enum { name: "Status" },
                Token::Str("online"),
                Token::Unit,
                Token::Str("web"),
                Token::Some,
                Token::Enum { name: "Status" },
                Token::Str("dnd"),
                Token::Unit,
                Token::StructEnd,
            ],
        );
    }
}