lib_wpsr/boxed/solution/letters_boxed/
shuffle.rs1use std::{fmt::Display, str::FromStr};
2
3use clap::Parser;
4
5#[derive(Clone, Debug, Default, Parser, PartialEq, Eq)]
6pub enum Shuffle {
7 #[default]
8 None,
9 Once,
10 Twice,
11}
12
13impl Shuffle {
14 pub fn new() -> Self {
15 Self::default()
16 }
17}
18
19impl FromStr for Shuffle {
20 type Err = String;
21 fn from_str(s: &str) -> Result<Self, Self::Err> {
22 match s.to_lowercase().as_str() {
23 "none" => Ok(Self::None),
24 "once" => Ok(Self::Once),
25 "twice" => Ok(Self::Twice),
26 _ => Err(format!("Invalid shuffle strategy: {s}")),
27 }
28 }
29}
30
31impl Display for Shuffle {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 Self::None => write!(f, "None"),
35 Self::Once => write!(f, "Once"),
36 Self::Twice => write!(f, "Twice"),
37 }
38 }
39}