File tree Expand file tree Collapse file tree 2 files changed +24
-20
lines changed
src/chromium/interoperability-with-cpp Expand file tree Collapse file tree 2 files changed +24
-20
lines changed Original file line number Diff line number Diff line change 33cxx requires you to declare the whole C++/Rust boundary in one of your ` .rs `
44files. For instance:
55
6- ``` rust
7- #[cxx:: bridge]
8- mod ffi {
9- extern " Rust" {
10- type MultiBuf ;
11-
12- fn next_chunk (buf : & mut MultiBuf ) -> & [u8 ];
13- }
14-
15- unsafe extern " C++" {
16- include! (" cxx-demo/include/blobstore.h" );
17-
18- type BlobstoreClient ;
19-
20- fn new_blobstore_client () -> UniquePtr <BlobstoreClient >;
21- fn put (& self , parts : & mut MultiBuf ) -> u64 ;
22- }
23- }
24-
25- // It's fine to put more Rust code here after your #[cxx::bridge]
6+ ``` rust,ignore
7+ {{#include ../../../third_party/cxx/book/snippets.rs:cxx_overview}}
268```
279
2810<details >
Original file line number Diff line number Diff line change @@ -119,3 +119,25 @@ fn main() {
119119 }
120120}
121121// ANCHOR_END: cpp_exception
122+
123+ // ANCHOR: cxx_overview
124+ #[ cxx:: bridge]
125+ mod ffi {
126+ extern "Rust" {
127+ type MultiBuf ;
128+
129+ fn next_chunk ( buf : & mut MultiBuf ) -> & [ u8 ] ;
130+ }
131+
132+ unsafe extern "C++" {
133+ include ! ( "example/include/blobstore.h" ) ;
134+
135+ type BlobstoreClient ;
136+
137+ fn new_blobstore_client ( ) -> UniquePtr < BlobstoreClient > ;
138+ fn put ( self : & BlobstoreClient , buf : & mut MultiBuf ) -> Result < u64 > ;
139+ }
140+ }
141+
142+ // Definitions of Rust types and functions go here
143+ // ANCHOR_END: cxx_overview
You can’t perform that action at this time.
0 commit comments