Skip to main content

api/dto/
score.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a player's score for API clients.
4///
5/// The score is split into back and front pegs, following standard cribbage scoring.
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
7pub struct ScoreDTO {
8    /// Position of the back peg.
9    pub back_peg: usize,
10
11    /// Position of the front peg.
12    pub front_peg: usize,
13}
14
15#[cfg(feature = "server")]
16mod server_only {
17    use server::domain::Position;
18
19    use super::*;
20
21    impl From<&Position> for ScoreDTO {
22        fn from(value: &Position) -> Self {
23            Self {
24                back_peg: value.back().value(),
25                front_peg: value.front().value(),
26            }
27        }
28    }
29}