plottery_project/project_params/
project_param.rs1use serde::{Deserialize, Serialize};
2
3use super::project_param_value::ProjectParamValue;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ProjectParam {
7 pub name: String,
8 pub value: ProjectParamValue,
9}
10
11impl PartialEq for ProjectParam {
12 fn eq(&self, other: &Self) -> bool {
13 let name_equal = self.name == other.name;
14 let type_equal = self.value.type_name() == other.value.type_name();
15
16 let range_equal = match (&self.value, &other.value) {
17 (
18 ProjectParamValue::FloatRanged { val: _, min, max },
19 ProjectParamValue::FloatRanged {
20 val: _,
21 min: min_other,
22 max: max_other,
23 },
24 ) => min == min_other && max == max_other,
25 (
26 ProjectParamValue::IntRanged { val: _, min, max },
27 ProjectParamValue::IntRanged {
28 val: _,
29 min: min_other,
30 max: max_other,
31 },
32 ) => min == min_other && max == max_other,
33 _ => true,
34 };
35
36 name_equal && type_equal && range_equal
37 }
38}
39
40impl ProjectParam {
41 pub fn new(name: &str, value: ProjectParamValue) -> Self {
42 Self {
43 name: name.to_string(),
44 value,
45 }
46 }
47
48 pub fn formatted_name(&self) -> String {
49 self.name.replace('_', " ").to_lowercase()
50 }
51}