Lines Matching +full:- +full:- +full:cxx
5 #[cxx::bridge]
16 The `extern "C++"` section of a CXX bridge declares C++ types and signatures to
28 # #[cxx::bridge]
46 MyType>`. This is to safeguard against things like mem::swap-ing the contents of
51 **Thread safety:** Be aware that CXX does not assume anything about the thread
53 CXX produces for you in Rust *do not* come with `Send` and `Sync` impls. If you
59 # #[cxx::bridge]
82 "Rust"](extern-rust.md)*** functions and methods. In particular, any signature
83 with a `self` parameter is interpreted as a C++ non-static member function and
87 in are accurate; that would be unreasonable. CXX performs static assertions that
95 each signature inside as safe-to-call or unsafe-to-call. If an extern block
96 contains at least one safe-to-call signature, it must be written as an `unsafe
101 #[cxx::bridge]
137 #[cxx::bridge]
145 fn create<'a>(res: &'a Resource) -> SharedPtr<TypeContainingBorrow<'a>>;
148 fn create(res: &Resource) -> SharedPtr<TypeContainingBorrow>;
158 non-interchangeable with the first.
161 #[cxx::bridge(namespace = "path::to")]
168 fn f(x: &MyType) -> usize;
174 Rust binding of C++'s `::path::to::MyType`, CXX will reuse the already existing
178 CXX safely validates that `crate::existing::MyType` is in fact a binding for the
181 automatically implemented by CXX for bindings that it generates but can also be
184 [`ExternType`]: https://docs.rs/cxx/*/cxx/trait.ExternType.html
190 In the following snippet, two #\[cxx::bridge\] invocations in different files
201 #[cxx::bridge(namespace = "example")]
206 fn create_demo() -> UniquePtr<Demo>;
213 #[cxx::bridge(namespace = "example")]
223 #### Integrating with bindgen-generated or handwritten unsafe bindings
226 emitted by bindgen as the definition of a C++ type emitted by CXX.
233 mod folly_sys; // the bindgen-generated bindings
235 use cxx::{type_id, ExternType};
239 type Kind = cxx::kind::Opaque;
242 #[cxx::bridge(namespace = "folly")]
254 // of the bindgen-generated signatures, we are able to pass it
258 The `ExternType::Id` associated type encodes a type-level representation of the
260 `type_id!` macro exposed in the cxx crate.
263 [`cxx::kind::Opaque`] or [`cxx::kind::Trivial`] identifying whether a C++ type
266 no destructor. In CXX, these are called Trivial extern C++ types, while types
270 [`cxx::kind::Opaque`]: https://docs.rs/cxx/*/cxx/kind/enum.Opaque.html
271 [`cxx::kind::Trivial`]: https://docs.rs/cxx/*/cxx/kind/enum.Trivial.html
278 # unsafe impl cxx::ExternType for TypeName {
279 # type Id = cxx::type_id!("name::space::of::TypeName");
280 type Kind = cxx::kind::Trivial;
285 value, and include it in `struct`s that you have declared to `cxx::bridge`. Your
293 CXX's support for C++'s std::unique\_ptr and std::vector is built on a set of
298 previous section, you may find that your code needs some trait impls which CXX
302 #[cxx::bridge]
310 // Okay: CXX sees UniquePtr<B> using a type B defined within the same
313 fn get_b() -> UniquePtr<B>;
317 #[cxx::bridge]
322 // Rust trait error: CXX processing this module has no visibility into
328 fn get_a() -> UniquePtr<A>;
339 #[cxx::bridge]
347 fn get_b() -> UniquePtr<B>;