tried 1
let value: &str = path_split[i];
const split_type: &str = match param_split.next() {
Some(x) => x,
_ => "String",
};
let parsed_value;
if split_type == "String" {
parsed_value = value.to_owned();
} else {
parsed_value = value.parse::<split_type>();
}
tried 2 with macro
#[macro_export]
macro_rules! type_conversion {
($ty:ty, $str:expr) => {{
let str: String = String::from($str);
match str.parse::<$ty>() {
Ok(x) => x.to_owned(),
_ => "".to_owned(),
}
}};
}
usage
type_conversion!("u32", "some string 123")