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

Provide example of providing a lifetime parameter #23

Closed
metasim opened this issue May 22, 2023 · 2 comments
Closed

Provide example of providing a lifetime parameter #23

metasim opened this issue May 22, 2023 · 2 comments

Comments

@metasim
Copy link

metasim commented May 22, 2023

I tried to use the generics support in foreign_types like this:

foreign_type! {
    pub unsafe type Feature<'a> {
        type CType = libc::c_void;
        type PhantomData = 'a;
        fn drop = feature_dtor;
    }
}

The compiler error I get is:

error: at least one trait is required for an object type
  --> src/foo/bar.rs:21:28
   |
21 |         type PhantomData = 'a;
   |                            ^^

Is there some other way of doing this using the macro? Or maybe I'm using it incorrectly?

@sfackler
Copy link
Owner

'a is a lifetime, not a type. See here for example of using &'a (): https://docs.rs/foreign-types/latest/foreign_types/macro.foreign_type.html#examples

@metasim
Copy link
Author

metasim commented May 23, 2023

@sfackler Perfect! Apologies for missing that example. Much appreciated.

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

2 participants