Skip to content

Commit 5d2f513

Browse files
committed
Update docs.
1 parent 1db5eb5 commit 5d2f513

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

docs.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,24 +299,9 @@ fn bar() -> Foo { .. } // Will be emitted as `struct foo bar();`
299299

300300
### Volatile annotation
301301

302-
cbindgen will emit the C volatile type qualifier for types and variables that have the `volatile=true` annotation.
302+
cbindgen will emit the C volatile type qualifier for transparent 1-field structs that have the `volatile` annotation.
303303

304-
There is no equivalent in rust. You should use `read_volatile` and `write_volatile` to get C-like behavior.
305-
306-
```rust
307-
/// cbindgen:volatile=true
308-
type volatile_type_t = u32;
309-
310-
#[repr(C)]
311-
struct S {
312-
/// cbindgen:volatile=true
313-
volatile_variable: u32,
314-
}
315-
316-
/// cbindgen:volatile=true
317-
#[no_mangle]
318-
static mut volatile_global_variable: u32 = 0;
319-
```
304+
Example usage can be found in `tests/rust/volatile.rs`.
320305

321306
### Struct Annotations
322307

tests/rust/volatile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This test uses the `cbindgen:volatile=true` annotation to generate volatile types and variables.
1+
//! This test uses the `volatile` annotation on a wrapper to generate volatile types.
22
33
use std::ffi::c_int;
44
use std::mem::ManuallyDrop;
@@ -8,7 +8,7 @@ use std::ptr::null_mut;
88
use std::ptr::NonNull;
99
use std::cell::Cell;
1010

11-
/// cbindgen:volatile=true
11+
/// cbindgen:volatile
1212
#[repr(transparent)]
1313
pub struct V<T>(T);
1414
impl<T> V<T> {
@@ -45,8 +45,8 @@ pub type c_vci = V<Cell<c_int>>;
4545

4646
pub type c_vfn = V<Option<extern "C" fn()>>;
4747

48-
// TODO not FFI-safe
49-
//pub type c_va2 = [V<c_int>; 2];
48+
// TODO cannot mangle array
49+
//pub type c_va2 = V<[c_int; 2]>;
5050

5151
#[repr(C)]
5252
pub struct S {

0 commit comments

Comments
 (0)