use syn::Type;
pub(crate) const SUPPORTED_INT_TYPES: &[&str] = &[
"i8", "i16", "i32", "i64", "i128", "u8", "u16", "u32", "u64", "u128",
];
pub(crate) const SUPPORTED_FLOAT_TYPES: &[&str] = &["f32", "f64"];
pub(crate) const SUPPORTED_RANGE_TYPES: &[&str] = &[
"i8", "i16", "i32", "i64", "i128", "u8", "u16", "u32", "u64", "u128", "f32", "f64",
];
pub(crate) fn is_supported_int_type(ty: &Type) -> bool {
SUPPORTED_INT_TYPES.contains(&type_to_string(ty).as_str())
}
pub(crate) fn is_supported_float_type(ty: &Type) -> bool {
SUPPORTED_FLOAT_TYPES.contains(&type_to_string(ty).as_str())
}
pub(crate) fn is_supported_range_type(ty: &Type) -> bool {
SUPPORTED_RANGE_TYPES.contains(&type_to_string(ty).as_str())
}
pub(crate) fn type_to_string(ty: &Type) -> String {
match ty {
Type::Path(type_path) => {
if let Some(ident) = type_path.path.get_ident() {
return ident.to_string();
}
type_path
.path
.segments
.last()
.map(|s| s.ident.to_string())
.unwrap_or_default()
}
_ => String::new(),
}
}