twilight_model/poll/
answer_count.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
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AnswerCount {
    /// The answer ID.
    pub id: u8,
    /// The number of votes for this answer.
    pub count: u64,
    /// Whether the current user voted for this answer.
    pub me_voted: bool,
}

#[cfg(test)]
mod tests {
    use super::AnswerCount;
    use serde_test::Token;

    #[test]
    fn answer_count() {
        let value = AnswerCount {
            id: 1,
            count: 2,
            me_voted: true,
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "AnswerCount",
                    len: 3,
                },
                Token::Str("id"),
                Token::U8(1),
                Token::Str("count"),
                Token::U64(2),
                Token::Str("me_voted"),
                Token::Bool(true),
                Token::StructEnd,
            ],
        );
    }
}