diff --git a/build.rs b/build.rs index 3844e13..9542b13 100644 --- a/build.rs +++ b/build.rs @@ -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> { - Int(&'a str, i32), + Int(&'a str, Num<'a>), String(&'a str, &'a str), } @@ -33,9 +49,9 @@ fn create_config_struct(content: &str, path: &str, struct_name: &str) { Variable::Int( name, if value.starts_with("0x") { - i32::from_str_radix(value.trim_start_matches("0x"), 16).unwrap() + Num::Hex(value) } else { - str::parse(value).unwrap() + Num::Dec(str::parse(value).unwrap()) }, ) }