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

#[node_bindgen] is broken? #41

Closed
crone123 opened this issue Jun 17, 2020 · 7 comments · Fixed by #42
Closed

#[node_bindgen] is broken? #41

crone123 opened this issue Jun 17, 2020 · 7 comments · Fixed by #42
Assignees
Labels
bug Something isn't working regression

Comments

@crone123
Copy link

Hello,
I have tried to use this library with this test code:

use node_bindgen::derive::node_bindgen;

pub struct MyStruct
{
    pub x: i64,
    pub y: i64,
}

#[node_bindgen]
impl MyStruct
{
    #[node_bindgen(constructor)]
    fn new(x: i64, y: i64) -> Self
    {
        MyStruct
        {
            x: x,
            y: y
        }
    }
    #[node_bindgen]
    fn hello(&self)
    {
        println!("MyStruct hello !");
    }
}

It works with version 1.3.0, but not with version 2.1.1.
On this latest version, I got this error:

  --> src/lib.rs:15:1
   |
15 | #[node_bindgen]
   | ^^^^^^^^^^^^^^^- help: missing `,`
   | |
   | expected one of 8 possible tokens
   |
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

In my case, the error concern the attribute used on the top of "impl MyStruct".
I have followed the examples, I don't know why it doesn't work.
Without this macro, it compiles but MyStruct is not available from nodejs.
Rust version: rustc 1.45.0-nightly (a74d1862d 2020-05-14) (on Linux 86_64)

Thank you !
Valentin CRÔNE

@sehz
Copy link
Collaborator

sehz commented Jun 17, 2020

Thanks for bug report.

Yes, I can reproduce it.

@sehz sehz added the bug Something isn't working label Jun 17, 2020
@sehz sehz self-assigned this Jun 17, 2020
@sehz
Copy link
Collaborator

sehz commented Jun 17, 2020

Yes, it works on 1.3.0 but not latest version. This happens whenever there are more than 1 field in the struct.

@sehz
Copy link
Collaborator

sehz commented Jun 17, 2020

This is interesting. Generated code looks ok and it even compiles but not from macro directly

sehz added a commit that referenced this issue Jun 17, 2020
add 2nd field class-simple to reproduce bug for struct with 2 fields
fix issue #41: fix macro expansion
instead of trying to manually inserting separator, let recursive
macro do for you
@sehz sehz linked a pull request Jun 17, 2020 that will close this issue
@sehz sehz closed this as completed in #42 Jun 17, 2020
sehz added a commit that referenced this issue Jun 17, 2020
add 2nd field class-simple to reproduce bug for struct with 2 fields
fix issue #41: fix macro expansion
instead of trying to manually inserting separator, let recursive
macro do for you
@sehz
Copy link
Collaborator

sehz commented Jun 17, 2020

fixed. previous implementation of macro expansion include extra ,. somehow it worked but I guess doesn't with latest version of quote library.

cargo update and it should work.

@crone123
Copy link
Author

Thank you !
Have I to change the version number in Cargo.toml or just cargo update?

@sehz
Copy link
Collaborator

sehz commented Jun 17, 2020

Cargo update should be enough

@crone123
Copy link
Author

Ok, it works, thank you ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants