dtolnay / cxx

Safe interop between Rust and C++
https://cxx.rs
Apache License 2.0
5.68k stars 322 forks source link

Add syntax support for "cxx::" prefix for c++ binding types. For example using `cxx::UniquePtr` instead of `UniquePtr`. #1308

Open tolvanea opened 5 months ago

tolvanea commented 5 months ago

I think it could prevent confusion if c++ binding types could be written with "cxx::" module perfix in the extern blocks. For example, in the Blobstore example we have

unsafe extern "C++" {
    include!("demo/include/blobstore.h");
    type BlobstoreClient;
    fn new_blobstore_client() -> UniquePtr<BlobstoreClient>;
    ...
}

If one writes the return type of new_blobstore_client() with cxx::UniquePtr<BlobstoreClient> instead, there is compilation error "unsupported type". Users may think cxx::UniquePtr to be the correct way write the type, because cxx namespace has not been opened up with use cxx::*;. The error message may misslead newcomers into thinking that there is something in their current interface design that is not supported by cxx.