cock_lib/cock_parts/
shape.rs1use crate::{FromString, GetVariants};
2
3#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
6pub enum Shape {
7 Cylindrical,
8 Tapered,
9 Other(String),
10}
11
12impl Shape {
13 pub fn get_shape(&self) -> &str {
15 match self {
16 Shape::Cylindrical => "Cylindrical",
17 Shape::Tapered => "Tapered",
18 Shape::Other(other) => other,
19 }
20 }
21}
22
23impl FromString for Shape {
26 fn from_string(shape: &str) -> Shape {
27 match shape {
28 "Cylindrical" => Shape::Cylindrical,
29 "Tapered" => Shape::Tapered,
30 "Other" => Shape::Other("".to_string()),
31 _ => panic!("Invalid shape"),
32 }
33 }
34}
35
36impl GetVariants for Shape {
38 fn get_variants() -> Vec<String> {
39 vec![
40 String::from("Cylindrical"),
41 String::from("Tapered"),
42 String::from("Other"),
43 ]
44 }
45}
46
47impl std::fmt::Display for Shape {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 match self {
53 Shape::Cylindrical => write!(f, "Cylindrical"),
54 Shape::Tapered => write!(f, "Tapered"),
55 Shape::Other(other) => write!(f, "{}", other),
56 }
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_shape() {
66 let cylindrical = Shape::Cylindrical;
67 let tapered = Shape::Tapered;
68 let other = Shape::Other(String::from("test"));
69
70 assert_eq!(cylindrical, Shape::Cylindrical);
71 assert_eq!(tapered, Shape::Tapered);
72 assert_eq!(other, Shape::Other(String::from("test")));
73 }
74}