In the simplified method below, within the macro test
, how can I invoke the static method len()
on a passed-in type?
trait Test {
fn len() -> usize { 1 }
}
impl Test for u8 {}
macro_rules! test {
($item_ty:ty) => (
println!("{}", $item_ty::len());
)
}
fn main() {
test!(u8); // ERROR
println!("{}", u8::len()); // runs fine
}
The code above gives the error
<anon>:8:24: 8:32 error: unexpected token: `u8`
<anon>:8 println!("{}", $item_ty::len());
^~~~~~~~