cock_lib/cock_parts/
curvature.rs1use crate::{FromString, GetVariants};
2
3#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
7pub enum Curvature {
8 Straight,
9 Left,
10 Right,
11 Upwards,
12 Downwards,
13 Other(String),
14}
15
16impl GetVariants for Curvature {
19 fn get_variants() -> Vec<String> {
20 vec![
21 String::from("Straight"),
22 String::from("Left"),
23 String::from("Right"),
24 String::from("Upwards"),
25 String::from("Downwards"),
26 String::from("Other"),
27 ]
28 }
29}
30
31impl FromString for Curvature {
35 fn from_string(curvature: &str) -> Curvature {
36 match curvature {
37 "Straight" => Curvature::Straight,
38 "Left" => Curvature::Left,
39 "Right" => Curvature::Right,
40 "Upwards" => Curvature::Upwards,
41 "Downwards" => Curvature::Downwards,
42 "Other" => Curvature::Other("".to_string()),
43 _ => panic!("Invalid curvature"),
44 }
45 }
46}
47
48impl std::fmt::Display for Curvature {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 match self {
55 Curvature::Straight => write!(f, "Straight"),
56 Curvature::Left => write!(f, "Left"),
57 Curvature::Right => write!(f, "Right"),
58 Curvature::Upwards => write!(f, "Upwards"),
59 Curvature::Downwards => write!(f, "Downwards"),
60 Curvature::Other(other) => write!(f, "{}", other),
61 }
62 }
63}
64#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_curvature() {
71 let straight = Curvature::Straight;
72 let left = Curvature::Left;
73 let right = Curvature::Right;
74 let upwards = Curvature::Upwards;
75 let downwards = Curvature::Downwards;
76 let other = Curvature::Other(String::from("test"));
77
78 assert_eq!(straight, Curvature::Straight);
79 assert_eq!(left, Curvature::Left);
80 assert_eq!(right, Curvature::Right);
81 assert_eq!(upwards, Curvature::Upwards);
82 assert_eq!(downwards, Curvature::Downwards);
83 assert_eq!(other, Curvature::Other(String::from("test")));
84 }
85}