cock_tier/modules/
cock_struct.rs

1use crate::{
2    Abnormalities, Aesthetic, Balls, Circumcision, Curvature, FromString, Inches, Shape, Size,
3    Veininess,
4};
5
6/// Struct representing detailed information about a [CockStruct]. Each property of a [CockStruct]
7/// is represented by a separate field, enabling fine-grained control and accurate descriptions.
8#[derive(Debug, Clone)]
9pub struct CockStruct {
10    pub size: Size,
11    pub aesthetic: Aesthetic,
12    pub balls: Balls,
13    pub shape: Shape,
14    pub curvature: Curvature,
15    pub circumcision: Circumcision,
16    pub veininess: Veininess,
17    pub abnormalities: Abnormalities,
18}
19
20impl CockStruct {
21    /// Constructor for creating a new instance of [CockStruct].
22    /// All parameters needed to fully describe a [CockStruct] are passed in as arguments.
23    pub fn new(
24        size: Size,
25        aesthetic: Aesthetic,
26        balls: Balls,
27        shape: Shape,
28        curvature: Curvature,
29        circumcision: Circumcision,
30        veininess: Veininess,
31        abnormalities: Abnormalities,
32    ) -> CockStruct {
33        CockStruct {
34            size,
35            aesthetic,
36            balls,
37            shape,
38            curvature,
39            circumcision,
40            veininess,
41            abnormalities,
42        }
43    }
44
45    /// Constructor for creating a new instance of [CockStruct] with the 'default' values.
46    pub fn default() -> CockStruct {
47        CockStruct {
48            size: Size {
49                length: 0.0,
50                girth: 0.0,
51                size_type: Inches,
52            },
53            aesthetic: Aesthetic::Normal,
54            balls: Balls::Normal,
55            shape: Shape::Other(String::from("")),
56            curvature: Curvature::Other(String::from("")),
57            circumcision: Circumcision::Uncircumcised,
58            veininess: Veininess::Normal,
59            abnormalities: Abnormalities::None,
60        }
61    }
62
63    /// Function for editing an existing instance of a [CockStruct] value.
64    /// The `part` parameter is used to specify which part of the [CockStruct] to edit.
65    /// The `new` parameter is used to specify the new value of the part.
66    pub fn from_str_part(&mut self, part: &str, new: &str) {
67        match part {
68            "Abnormalities" => self.abnormalities = Abnormalities::from_string(new),
69            "Aesthetic" => self.aesthetic = Aesthetic::from_string(new),
70            "Balls" => self.balls = Balls::from_string(new),
71            "Circumcision" => self.circumcision = Circumcision::from_string(new),
72            "Curvature" => self.curvature = Curvature::from_string(new),
73            "Shape" => self.shape = Shape::from_string(new),
74            "Veininess" => self.veininess = Veininess::from_string(new),
75            _ => panic!("Invalid part"),
76        }
77    }
78
79    /// Function for editing an existing instance of a [CockStruct] value.
80    /// The `item` parameter is used to verify whether the current [CockStruct] value requires a user submitted value.
81    /// [Abnormalities::Major], [Abnormalities::Minor], [Shape::Other], and [Curvature::Other] all require a user submitted value.
82    /// The `part` parameter is used to specify which part of the [CockStruct] to edit ("Abnormalities", "Shape", "Curvature").
83    /// The `new` parameter is used to specify the new value of the part.
84    pub fn get_custom(&mut self, part: &str, item: &str, new: &str) {
85        match item {
86            "Major" => self.abnormalities = Abnormalities::Major(new.to_string()),
87            "Minor" => self.abnormalities = Abnormalities::Minor(new.to_string()),
88            "Other" => match part {
89                "Shape" => self.shape = Shape::Other(new.to_string()),
90                "Curvature" => self.curvature = Curvature::Other(new.to_string()),
91                _ => panic!("Invalid part"),
92            },
93            _ => panic!("Invalid item"),
94        }
95    }
96}
97
98/// This implementation of [std::fmt::Display] allows a [CockStruct] to be converted to a string for easy display.
99impl std::fmt::Display for CockStruct {
100    /// Returns a string representation of a [CockStruct].
101    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
102        writeln!(f, "Size: {}", self.size)?;
103        writeln!(f, "Aesthetic: {}", self.aesthetic)?;
104        writeln!(f, "Balls: {}", self.balls)?;
105        writeln!(f, "Shape: {}", self.shape)?;
106        writeln!(f, "Curvature: {}", self.curvature)?;
107        writeln!(f, "Circumcision: {}", self.circumcision)?;
108        writeln!(f, "Veininess: {}", self.veininess)?;
109        write!(f, "Abnormalities: {}", self.abnormalities)
110    }
111}
112
113#[cfg(test)]
114mod tests {
115    use super::*;
116    use crate::Inches;
117
118    #[test]
119    fn cock_struct_test() {
120        let cock = CockStruct::new(
121            Size {
122                length: 5.6,
123                girth: 4.1,
124                size_type: Inches,
125            },
126            Aesthetic::UglyButUsable,
127            Balls::PossibleCancer,
128            Shape::Other(String::from("test")),
129            Curvature::Right,
130            Circumcision::Circumcised,
131            Veininess::HealthyPumper,
132            Abnormalities::Major(String::from("Active case of herpes")),
133        );
134
135        assert_eq!(cock.size.length, 5.6);
136        assert_eq!(cock.size.girth, 4.1);
137        assert_eq!(cock.size.size_type, Inches);
138        assert_eq!(cock.aesthetic, Aesthetic::UglyButUsable);
139        assert_eq!(cock.balls, Balls::PossibleCancer);
140        assert_eq!(cock.shape.get_shape(), "test");
141        assert_eq!(cock.curvature, Curvature::Right);
142        assert_eq!(cock.circumcision, Circumcision::Circumcised);
143        assert_eq!(cock.veininess, Veininess::HealthyPumper);
144        assert_eq!(
145            cock.abnormalities.get_abnormality(),
146            "Active case of herpes"
147        );
148    }
149}