Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Separate declaration of type using macro_rules!
How can I correctly declare type inside declarative macro by separating type's name itself and it's generics ?
Consider this example:
struct RectangleA<const WIDTH: usize, const LENGTH: usise>;
struct RectangleB<const WIDTH: usize, const LENGTH: usise>;
I want to separate type declaration (and possibly it's genercics) between few macroses to match on different parameters. I see it like this:
macro_rules! get_type {
(false) => {
RectangleA
}
(true) => {
RectangleB
}
}
macro_rules! impl_something {
($SOME_FLAG: expr) => {
get_type!($SOME_FLAG)::<5, 10>
}
}
7 posts - 4 participants
🏷️ rust_feed