syn
syn copied to clipboard
Is there any way to get the Type what Type::Path points to?
I want to check if a type is a large const sized array,
fn big_array_p(ty: &Type) -> bool {
match ty {
Type::Array(n) => match &n.len {
Expr::Lit(lit) => match &lit.lit {
Lit::Int(size) => {
if let Ok(size) = size.base10_parse::<u32>() {
// big array size > 32
if size > 32 {
return true;
}
}
}
_ => {}
},
_ => {}
},
Type::Path(p) => {
println!("{:?} {:?}", p.path, p.qself);
}
_ => {}
}
false
}
The Type::Array branch works well for the struct:
struct Big {
pub field: [u8; 100],
}
But failed with the type alias version:
pub type B = [u8; 100],
struct Big {
pub field: B,
}
Could I complete the Type::Path branch with what I need?
I read some of the source of syn, but seems the Path type does not hold the real type info which the Path points to.