0

I'd like to write a macro with the shape:

macro_rules! build {
    ($name:ident, $mask:ty, $end:expr)  => {
        enum $name<K, V {
            //???
        }
    };
}

Such that when invoked with:

build! {
    Node, u64, 64
}

It expands to:

enum Node<K, V> {
    Node1(u64, Box<[Node<K, V>; 1]>),
    Node2(u64, Box<[Node<K, V>; 2]>),
    // ...
    Node64(u64, Box<[Node<K, V>; 64]>),
}

Is this possible with macro_rules?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
saik0
  • 118
  • 5
  • Why not use `Box<[T]>` like `struct Node(u64, Box<[Node]>)` in this case? The data layout seems almost the same except for the maximum length of the array and the order of the fields. – Masaki Hara Jul 15 '17 at 16:04
  • 1
    No, you cannot generate new identifiers (`Node1`, `Node2`, ...) in a macro. – Shepmaster Jul 15 '17 at 16:12

0 Answers0