Closed emberian closed 7 years ago
I don't think this is possible with the current macro_rules!
syntax. We could revisit this once rust-lang/rfcs#1583 lands, since it adds the ability to parse a generic argument list with macros.
For now you'll just have to manually implement the IntrusiveAdaptor
trait.
It is possible in a limited way: you can't have bounds on the type parameters. This is still useful in the short term I think. (I'm working on a patch right now)
Well, I thought it was possible, seems not. Oh well.
Fixed in 0.5.0.
I am trying to make this work for a struct with two type parameters, like this:
pub struct ObjectSet<T, U> {
set_list: linked_list::Link,
pub objects: Vec<Object<T>>,
pub metadata: U,
}
intrusive_adapter!(ObjectSetAdapter<T, U> = Box<ObjectSet<T, U>>: ObjectSet<T, U> { set_list: linked_list::Link });
However I'm getting this compiler error:
error: expected one of `,`, `:`, `=`, or `>`, found `T`
|
53 | intrusive_adapter!(ObjectSetAdapter<T, U> = Box<ObjectSet<T,U>>: ObjectSet<T,U> { set_list: linked_list::Link });
| ^ - expected one of `,`, `:`, `=`, or `>` here
| |
| unexpected token
The compiler didn't complain about a similar intrusive_adapter! with one type argument.
Can you tell if I'm doing something wrong or if this might be a bug?
Fixed in 0.6.2.
Thanks :)
It would be nice to have the macro able to generate generic adaptors. For example, to make using the following nice:
(Macro syntax come up with on-the-spot, not sure if that would parse)