Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic intrusive adaptors #1

Closed
emberian opened this issue Apr 22, 2016 · 7 comments
Closed

Generic intrusive adaptors #1

emberian opened this issue Apr 22, 2016 · 7 comments

Comments

@emberian
Copy link

emberian commented Apr 22, 2016

It would be nice to have the macro able to generate generic adaptors. For example, to make using the following nice:

pub struct Node<T> {
    link: linked_list::Link,
    val: T,
}

intrusive_adaptor!(for <T> List = Object<T> { free_list: linked_list::Link});

(Macro syntax come up with on-the-spot, not sure if that would parse)

@Amanieu
Copy link
Owner

Amanieu commented Apr 22, 2016

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.

@emberian
Copy link
Author

emberian commented Apr 22, 2016

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)

@emberian
Copy link
Author

Well, I thought it was possible, seems not. Oh well.

@Amanieu
Copy link
Owner

Amanieu commented Mar 30, 2017

Fixed in 0.5.0.

@Amanieu Amanieu closed this as completed Mar 30, 2017
@canarysnort01
Copy link

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?

@Amanieu
Copy link
Owner

Amanieu commented May 28, 2017

Fixed in 0.6.2.

@canarysnort01
Copy link

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants