Skip to content

Commit ee31be0

Browse files
committed
Stow cxx example code in third_party
1 parent 0c5f31d commit ee31be0

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/chromium/interoperability-with-cpp/example-bindings.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,8 @@
33
cxx requires you to declare the whole C++/Rust boundary in one of your `.rs`
44
files. 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>

third_party/cxx/book/snippets.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)