1#[derive(Debug, Copy, Clone, PartialEq, Eq)]
21pub enum ArgumentValue<'a> {
22 String(&'a str),
24
25 Integer(i32),
27
28 Boolean(bool),
30
31 Null,
34}
35
36impl<'a> From<Option<&'a str>> for ArgumentValue<'a> {
37 #[inline]
38 fn from(value: Option<&'a str>) -> Self {
39 match value {
40 Some(value) => ArgumentValue::from(value),
41 None => ArgumentValue::Null,
42 }
43 }
44}
45
46impl<'a> From<&'a str> for ArgumentValue<'a> {
47 fn from(value: &'a str) -> Self {
48 const SPECIAL_VALUES: [(&str, ArgumentValue); 5] = [
49 ("", ArgumentValue::Null),
50 ("t", ArgumentValue::Boolean(true)),
51 ("f", ArgumentValue::Boolean(false)),
52 ("true", ArgumentValue::Boolean(true)),
53 ("false", ArgumentValue::Boolean(false)),
54 ];
55
56 for (name, result) in &SPECIAL_VALUES {
57 if name.eq_ignore_ascii_case(value) {
58 return *result;
59 }
60 }
61
62 match value.parse::<i32>() {
63 Ok(int) => ArgumentValue::Integer(int),
64 Err(_) => ArgumentValue::String(value),
65 }
66 }
67}
68
69impl From<bool> for ArgumentValue<'_> {
70 #[inline]
71 fn from(value: bool) -> Self {
72 ArgumentValue::Boolean(value)
73 }
74}
75
76impl From<i32> for ArgumentValue<'_> {
77 #[inline]
78 fn from(value: i32) -> Self {
79 ArgumentValue::Integer(value)
80 }
81}
82
83impl From<()> for ArgumentValue<'_> {
84 #[inline]
85 fn from(_: ()) -> Self {
86 ArgumentValue::Null
87 }
88}