Skip to main content

lichess_api/model/games/stream/
moves.rs

1use crate::model::Variant;
2use crate::model::games::Players;
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Default, Clone, Debug, Serialize)]
7pub struct GetQuery;
8
9pub type GetRequest = crate::model::Request<GetQuery>;
10
11impl GetRequest {
12    pub fn new(id: &str) -> Self {
13        Self::get(format!("/api/stream/game/{id}"), None, None)
14    }
15}
16
17impl<S: AsRef<str>> From<S> for GetRequest {
18    fn from(s: S) -> Self {
19        Self::new(s.as_ref())
20    }
21}
22
23pub type Move = MoveStream;
24
25#[derive(Clone, Debug, Deserialize, Serialize)]
26#[serde(untagged)]
27// Boxing would ripple through every match arm across the crate for a rarely-streamed enum; not worth it.
28#[allow(clippy::large_enum_variant)]
29pub enum MoveStream {
30    #[serde(rename_all = "camelCase")]
31    Start {
32        id: String,
33        variant: Variant,
34        speed: String,
35        perf: String,
36        rated: bool,
37        #[serde(skip_serializing_if = "Option::is_none")]
38        initial_fen: Option<String>,
39        fen: String,
40        player: String,
41        turns: u32,
42        #[serde(skip_serializing_if = "Option::is_none")]
43        started_at_turn: Option<u64>,
44        source: String,
45        status: Status,
46        created_at: u64,
47        #[serde(skip_serializing_if = "Option::is_none")]
48        last_move: Option<String>,
49        #[serde(skip_serializing_if = "Option::is_none")]
50        players: Option<Players>,
51    },
52    Move {
53        fen: String,
54        #[serde(rename = "lm")]
55        #[serde(skip_serializing_if = "Option::is_none")]
56        last_move: Option<String>,
57        #[serde(rename = "wc")]
58        #[serde(skip_serializing_if = "Option::is_none")]
59        white_centipawns: Option<u32>,
60        #[serde(rename = "bc")]
61        #[serde(skip_serializing_if = "Option::is_none")]
62        black_centipawns: Option<u32>,
63    },
64}
65
66#[derive(Clone, Debug, Serialize, Deserialize)]
67pub struct Status {
68    pub id: u64,
69    pub name: String,
70}