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 (253 forks)batch import
help wanted

Repository metrics

Stars
 (4,472 stars)
PR merge metrics
 (Avg merge 8m) (3 merged PRs in 30d)

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