Lines Matching refs:Rust
1 CXX — safe FFI between Rust and C++
9 This library provides a **safe** mechanism for calling C++ code from Rust and
10 Rust code from C++, not subject to the many ways that things can go wrong when
14 project, you would be on the hook for auditing all the unsafe Rust code and
16 just the C++ side would be sufficient to catch all problems, i.e. the Rust side
42 embedded together in one Rust module (the next section shows an example). From
44 against the types and function signatures to uphold both Rust's and C++'s
50 correctness. On the Rust side this code generator is simply an attribute
60 such as Rust's `String` or C++'s `std::string`, Rust's `Box` or C++'s
61 `std::unique_ptr`, Rust's `Vec` or C++'s `std::vector`, etc in any combination.
65 from Rust, its `len()` method becomes a call of the `size()` member function
66 defined by C++; when manipulating a Rust string from C++, its `size()` member
67 function calls Rust's `len()`.
73 In this example we are writing a Rust application that wishes to take advantage
91 extern "Rust" {
93 // only Rust can see the fields.
96 // Functions implemented in Rust.
119 Now we simply provide Rust definitions of all the things in the `extern "Rust"`
134 # run Rust code generator and print to stdout
154 such as a reference `&`, a Rust `Box`, or a `UniquePtr`. Can be a type alias
161 Within the `extern "Rust"` part of the CXX bridge we list the types and
162 functions for which Rust is the source of truth. These all implicitly refer to
175 Your function implementations themselves, whether in C++ or Rust, *do not* need
184 are typed out once where the implementation is defined (in C++ or Rust) and
197 bindgen-like tool on top of CXX which consumes a C++ header and/or Rust module
205 raw pointer functions, applying bindgen to get unsafe raw pointer Rust
206 functions, and replicating the API again to expose those idiomatically in Rust.
287 the FFI boundary. Ordinarily in Rust writing your own `extern "C"` blocks is
288 unsafe because the Rust compiler has no way to know whether the signatures
294 be passed by value from C++ to Rust, for example because they may contain
295 internal pointers that would be screwed up by Rust's move behavior.
297 - To many people's surprise, it is possible to have a struct in Rust and a
307 in Rust backed by a real C++ unique\_ptr, we have a way of using a Rust trait
322 <tr><th>name in Rust</th><th>name in C++</th><th>restrictions</th></tr>
329 …;</a></td><td>std::unique_ptr<T></td><td><sup><i>cannot hold opaque Rust type</i></sup></td>…
330 …;</a></td><td>std::shared_ptr<T></td><td><sup><i>cannot hold opaque Rust type</i></sup></td>…
333 …or<T></td><td><sup><i>cannot be passed by value, cannot hold opaque Rust type</i></sup></td>…
335 <tr><td>fn(T, U) -> V</td><td>rust::Fn<V(T, U)></td><td><sup><i>only passing from Rust to …
348 <tr><th>name in Rust</th><th>name in C++</th></tr>
369 Finally, I know more about Rust library design than C++ library design so I