Debian Codegraph @

src/options/option_value.rs

raw symbols SCIP
1 use crate::config::delta_unreachable;
2
3 /// A value associated with a Delta command-line option name.
4 pub enum OptionValue {
5 Boolean(bool),
6 Float(f64),
7 OptionString(Option<String>),
8 String(String),
9 Int(usize),
10 }
11
12 /// An OptionValue, tagged according to its provenance/semantics.
13 pub enum ProvenancedOptionValue {
14 GitConfigValue(OptionValue),
15 DefaultValue(OptionValue),
16 }
17
18 impl From<bool> for OptionValue {
19 fn from(value: bool) -> Self {
20 OptionValue::Boolean(value)
21 }
22 }
23
24 impl From<OptionValue> for bool {
25 fn from(value: OptionValue) -> Self {
26 match value {
27 OptionValue::Boolean(value) => value,
28 _ => delta_unreachable("Error converting OptionValue to bool."),
29 }
30 }
31 }
32
33 impl From<f64> for OptionValue {
34 fn from(value: f64) -> Self {
35 OptionValue::Float(value)
36 }
37 }
38
39 impl From<OptionValue> for f64 {
40 fn from(value: OptionValue) -> Self {
41 match value {
42 OptionValue::Float(value) => value,
43 _ => delta_unreachable("Error converting OptionValue to f64."),
44 }
45 }
46 }
47
48 impl From<Option<String>> for OptionValue {
49 fn from(value: Option<String>) -> Self {
50 OptionValue::OptionString(value)
51 }
52 }
53
54 impl From<OptionValue> for Option<String> {
55 fn from(value: OptionValue) -> Self {
56 match value {
57 OptionValue::OptionString(value) => value,
58 _ => delta_unreachable("Error converting OptionValue to Option<String>."),
59 }
60 }
61 }
62
63 impl From<String> for OptionValue {
64 fn from(value: String) -> Self {
65 OptionValue::String(value)
66 }
67 }
68
69 impl From<&str> for OptionValue {
70 fn from(value: &str) -> Self {
71 value.to_string().into()
72 }
73 }
74
75 impl From<OptionValue> for String {
76 fn from(value: OptionValue) -> Self {
77 match value {
78 OptionValue::String(value) => value,
79 _ => delta_unreachable("Error converting OptionValue to String."),
80 }
81 }
82 }
83
84 impl From<usize> for OptionValue {
85 fn from(value: usize) -> Self {
86 OptionValue::Int(value)
87 }
88 }
89
90 impl From<OptionValue> for usize {
91 fn from(value: OptionValue) -> Self {
92 match value {
93 OptionValue::Int(value) => value,
94 _ => delta_unreachable("Error converting OptionValue to usize."),
95 }
96 }
97 }