pub unsafe trait ValueParam<T> { }
Expand description
A trait representing a parameter to a C++ function which is received by value.
Rust has the concept of receiving parameters by move or by reference. C++ has the concept of receiving a parameter by ‘value’, which means the parameter gets copied.
To make it easy to pass such parameters from Rust, this trait exists.
It is implemented both for references &T
and for UniquePtr<T>
,
subject to the presence or absence of suitable copy and move constructors.
This allows you to pass in parameters by copy (as is ergonomic and normal
in C++) retaining the original parameter; or by move semantics thus
destroying the object you’re passing in. Simply use a reference if you want
copy semantics, or the item itself if you want move semantics.
It is not recommended that you implement this trait, nor that you directly
use its methods, which are for use by autocxx
generated code only.
§Use of moveit
traits
Most of the implementations of this trait require the type to implement
CopyNew
, which is simply the autocxx
/moveit
way of saying that
the type has a copy constructor in C++.
§Being explicit
If you wish to explicitly force either a move or a copy of some type,
use as_mov
or as_copy
.
§Performance
At present, some additional copying occurs for all implementations of
this trait other than that for cxx::UniquePtr
. In the future it’s
hoped that the implementation for &T where T: CopyNew
can also avoid
this extra copying.
§Panics
The implementations of this trait which take a cxx::UniquePtr
will
panic if the pointer is NULL.
§Safety
Implementers must guarantee that the pointer returned by get_ptr
is of the correct size and alignment of T
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.