count_tys!() function-like macro
Returns the count of comma-delimited :ty
s (types) in the given TokenStream
as a constant expression of type usize
Arguments
input
- ATokenStream
in which comma-delimited:ty
s (types) must be counted
Examples
Basic usage
// count_tys!($($ty:ty),*)
More complete example
Cargo.toml
/*
[dependencies]
proc-macro-hack = "0.5"
count-tys = "0.1"
*/
main.rs
extern crate proc_macro_hack;
use proc_macro_hack;
use count_tys;
// It not necessarily must be a struct, it could be a generic
// Read more about macro_rules! here:
// <https://doc.rust-lang.org/rust-by-example/macros.html>
;
}
// declare_variadic_struct!(VariadicStruct, <usize, usize, usize>);
// expands into the following:
//
// struct VariadicStruct {
// // fields
// }
//
// impl VariadicStuct {
// pub const fn count() -> usize {
// 3usize
// }
// }
declare_variadic_struct!;
assert_eq!;