mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
795 stars 44 forks source link

cpp! macro with empty capture #66

Closed benkay86 closed 5 years ago

benkay86 commented 5 years ago

Would it be possible to add support for using the cpp! macro without passing anything in from rust? For symmetry one might add support to the rust! macro to do the same. For example:

    cpp!(unsafe [ ] { std::cout << "Hello world!\n"; });
    let the_answer : i32 = cpp!(unsafe [ ] -> i32 as "int32_t" { return 42; });
ogoffart commented 5 years ago

This is working fine for me.

This is even tested there:

https://github.com/mystor/rust-cpp/blob/9b62bf4d573faea64c9c87c2f408f939b2a13dfe/test/src/lib.rs#L144-L150

What version are you using? What error do you get?

benkay86 commented 5 years ago

You are quite right, this issue is invalid. The compiler was generating a misleading error from within the macro for a more complicated test case. The macro is working exactly as it should.

ogoffart commented 5 years ago

What was the misleading error? Perhaps this can be improved?