Keep hex representation

This commit is contained in:
hodasemi 2023-04-13 14:30:48 +02:00
parent 3abd04f0a6
commit dc62866577

View file

@ -1,5 +1,21 @@
use std::fmt;
enum Num<'a> {
Hex(&'a str),
Dec(i32),
}
impl<'a> fmt::Display for Num<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Num::Hex(h) => write!(f, "{h}"),
Num::Dec(d) => write!(f, "{d}"),
}
}
}
enum Variable<'a> { enum Variable<'a> {
Int(&'a str, i32), Int(&'a str, Num<'a>),
String(&'a str, &'a str), String(&'a str, &'a str),
} }
@ -33,9 +49,9 @@ fn create_config_struct(content: &str, path: &str, struct_name: &str) {
Variable::Int( Variable::Int(
name, name,
if value.starts_with("0x") { if value.starts_with("0x") {
i32::from_str_radix(value.trim_start_matches("0x"), 16).unwrap() Num::Hex(value)
} else { } else {
str::parse(value).unwrap() Num::Dec(str::parse(value).unwrap())
}, },
) )
} }