mystor / rust-cpp

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

Edition 2018 support: macro imports #69

Closed curiousleo closed 4 years ago

curiousleo commented 4 years ago

Rust 2018 brings Path Clarity.

The current crate example uses pre-"Path Clarity" syntax to import the cpp! macro: https://docs.rs/cpp/0.5.4/cpp/#librs.

Using the example without extern crate (as is the new default according to my understanding of the 2018 edition documentation) looks like this:

use cpp::{cpp, __cpp_internal, __cpp_internal_closure};

cpp!{{
    #include <iostream>
}}

fn main() {
    let name = std::ffi::CString::new("World").unwrap();
    let name_ptr = name.as_ptr();
    let r = unsafe {
        cpp!([name_ptr as "const char *"] -> u32 as "int32_t" {
            std::cout << "Hello, " << name_ptr << std::endl;
            return 42;
        })
    };
    assert_eq!(r, 42)
}

It works, but only when bringing the internal macros __cpp_internal and __cpp_internal_closure into scope.

Perhaps there is a way to structure the macros such that

use cpp::cpp;

is all that's need to use the cpp! macro in a 2018 edition Rust project?

ogoffart commented 4 years ago

Right, i guess it should be fixed to use $crate::__cpp_internal and so for all macro. Do you want to do the change?