1use crate::player::PlayerId;
4
5#[derive(Clone, PartialEq, Eq, Debug)]
12#[non_exhaustive]
13pub enum Error {
14 IllegalAction {
16 player: PlayerId,
18 },
19 NotActive {
21 player: PlayerId,
23 },
24}
25
26impl core::fmt::Display for Error {
27 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
28 match self {
29 Self::IllegalAction { player } => {
30 write!(f, "illegal action for {player}")
31 }
32 Self::NotActive { player } => {
33 write!(f, "{player} is not active")
34 }
35 }
36 }
37}
38
39impl std::error::Error for Error {}
40
41#[cfg(test)]
42mod tests {
43 use super::Error;
44 use crate::player::PlayerId;
45
46 #[test]
47 fn display_mentions_the_player() {
48 let e = Error::IllegalAction {
49 player: PlayerId::new(1),
50 };
51 assert_eq!(e.to_string(), "illegal action for p1");
52 }
53}