dtolnay / cxx

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

Functions and opaque types with type parameters #767

Closed smessmer closed 3 years ago

smessmer commented 3 years ago

For writing rust libraries wrapping C++ libraries where the C++ API makes heavy use of templated types, the current cxx.rs implementation needs you to create an opaque type and function for each template instantiation. It would be nice if we could build direct bindings for the template instead:

// C++
template<class T> std::unique_ptr<APIObject<T>> method(); 
// Rust
#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        type APIObject<T>;

        fn method<T>() -> UniquePtr<APIObject<T>>;
    }
}

I think this would hugely simplify writing rust wrappers for existing C++ libraries.

adetaylor commented 3 years ago

This is probably a duplicate of #683.

smessmer commented 3 years ago

closing as duplicate