Additional Types
| Rust Type | C++ Type |
|---|---|
String |
rust::String |
&str |
rust::Str |
CxxString |
std::string |
&[T]/&mut [T] |
rust::Slice |
Box<T> |
rust::Box<T> |
UniquePtr<T> |
std::unique_ptr<T> |
Vec<T> |
rust::Vec<T> |
CxxVector<T> |
std::vector<T> |
- These types can be used in the fields of shared structs and the arguments and returns of extern functions.
- Note that Rust’s
Stringdoes not map directly tostd::string. There are a few reasons for this: std::stringdoes not uphold the UTF-8 invariant thatStringrequires.- The two types have different layouts in memory and so can’t be passed directly between languages.
std::stringrequires move constructors that don’t match Rust’s move semantics, so astd::stringcan’t be passed by value to Rust.
