1use std::str::FromStr;
2
3#[derive(Debug, Clone, PartialEq)]
5pub struct ParamSummary {
6 name: String,
7 description: Option<String>,
8 value: Option<String>,
9 default_value: Option<String>,
10 provided: bool,
11}
12
13impl ParamSummary {
15
16 pub fn with_name<
18 S: Into<String>,
19 >(
20 name: S,
21 description: Option<String>,
22 value: Option<String>,
23 default_value: Option<String>,
24 provided: bool,
25 ) -> Self {
26 Self {
27 name: name.into(),
28 description,
29 value,
30 default_value,
31 provided,
32 }
33 }
34}
35
36impl ParamSummary {
38
39 pub fn name(&self) -> &String {
41 &self.name
42 }
43
44 pub fn description(&self) -> &Option<String> {
46 &self.description
47 }
48
49 pub fn value(&self) -> &Option<String> {
51 &self.value
52 }
53
54 pub fn to_value<T>(&self) -> Option<T>
56 where
57 T: FromStr,
58 {
59 match &self.value {
60 Some(v) => match v.parse::<T>() {
61 Ok(v) => Some(v),
62 Err(_) => None,
63 },
64 None => None,
65 }
66 }
67
68 pub fn default_value(&self) -> &Option<String> {
70 &self.default_value
71 }
72
73 pub fn provided(&self) -> bool {
75 self.provided
76 }
77}