// rust/cxx.h#include<type_traits>namespace rust {
template <typename T>
classBoxfinal {public:
using element_type = T;
using const_pointer =
typenamestd::add_pointer<typenamestd::add_const<T>::type>::type;
using pointer = typenamestd::add_pointer<T>::type;
Box(Box &&) noexcept;
~Box() noexcept;
explicitBox(const T &);
explicitBox(T &&);
Box &operator=(Box &&) noexcept;
const T *operator->() constnoexcept;
const T &operator*() constnoexcept;
T *operator->() noexcept;
T &operator*() noexcept;
template <typename... Fields>
static Box in_place(Fields &&...);
voidswap(Box &)noexcept;
// Important: requires that `raw` came from an into_raw call. Do not// pass a pointer from `new` or any other source.static Box from_raw(T *)noexcept;
T *into_raw()noexcept;
};
} // namespace rust
Box<T> does not support T being an opaque C type. You should use
UniquePtr<T> or SharedPtr<T> instead for
transferring ownership of opaque C types on the language boundary.
If T is an opaque Rust type, the Rust type is required to be Sized i.e. size
known at compile time. In the future we may introduce support for dynamically
sized opaque Rust types.
This program uses a Box to pass ownership of some opaque piece of Rust state
over to C and then back to a Rust callback, which is a useful pattern for
implementing async functions over FFI.