File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 7373//!
7474//! ```c
7575//! /* C header */
76- //!
76+ //!
7777//! /* Returns ownership to the caller */
7878//! struct Foo* foo_new(void);
79- //!
79+ //!
8080//! /* Takes ownership from the caller; no-op when invoked with NULL */
8181//! void foo_delete(struct Foo*);
8282//! ```
83- //!
83+ //!
8484//! These two functions might be implemented in Rust as follows. Here, the
8585//! `struct Foo*` type from C is translated to `Box<Foo>`, which captures
8686//! the ownership constraints. Note also that the nullable argument to
9999//! #[no_mangle]
100100//! pub extern "C" fn foo_delete(_: Option<Box<Foo>>) {}
101101//! ```
102- //!
102+ //!
103103//! Even though `Box<T>` has the same representation and C ABI as a C pointer,
104104//! this does not mean that you can convert an arbitrary `T*` into a `Box<T>`
105105//! and expect things to work. `Box<T>` values will always be fully aligned,
You can’t perform that action at this time.
0 commit comments