dtolnay/cxx

Box clone() member function to call Clone on opaque Rust types

Open

#105 opened on Apr 11, 2020

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Rust (4,472 stars) (253 forks)batch import
help wanted

Description

We should provide a way to constrain that some opaque Rust type implements Clone and then expose the Clone impl to C++ via a clone() member function on rust::Box.

Something like:

mod ffi {
    extern "Rust" {
        type ClonableR: Clone;
    }

    extern "C++" {
        fn f(b: Box<ClonableR>); // C++ will be able to clone b
    }
}
  template <typename T>
  class Box {
+   Box clone() const noexcept;
  };

Contributor guide