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
use serde::{
    de::{Deserialize, Deserializer, MapAccess, Visitor},
    ser::{Serialize, SerializeMap, Serializer},
};
use std::fmt::{self, Formatter};

/// A placeholder currently holding no information. See [Bots API docs].
///
/// [Bots API docs]: https://core.telegram.org/bots/api#callbackgame
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Default)]
pub struct Game;

impl Serialize for Game {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        serializer.serialize_map(Some(0))?.end()
    }
}

struct GameVisitor;

impl<'v> Visitor<'v> for GameVisitor {
    type Value = Game;

    fn expecting(&self, fmt: &mut Formatter) -> fmt::Result {
        write!(fmt, "struct Game")
    }

    fn visit_map<V>(self, _map: V) -> Result<Self::Value, V::Error>
    where
        V: MapAccess<'v>,
    {
        Ok(Game)
    }
}

impl<'de> Deserialize<'de> for Game {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        deserializer.deserialize_struct("Game", &[], GameVisitor)
    }
}