File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 6363//! T` obtained from `Box::<T>::into_raw` may be deallocated using the
6464//! [`Global`] allocator with `Layout::for_value(&*value)`.
6565//!
66+ //! `Box<T>` has the same representation as `*mut T`. In particular, when
67+ //! `T: Sized`, this means that `Box<T>` has the same representation as
68+ //! a C pointer, making the following code valid in FFI:
69+ //!
70+ //! ```c
71+ //! /* C header */
72+ //! struct Foo* foo(); /* Returns ownership */
73+ //! void bar(struct Foo*); /* `bar` takes ownership */
74+ //! ```
75+ //!
76+ //! ```
77+ //! #[repr(C)]
78+ //! pub struct Foo;
79+ //!
80+ //! #[no_mangle]
81+ //! pub extern "C" fn foo() -> Box<Foo> {
82+ //! Box::new(Foo)
83+ //! }
84+ //!
85+ //! #[no_mangle]
86+ //! pub extern "C" fn bar(_: Option<Box<Foo>>) {}
87+ //! ```
6688//!
6789//! [dereferencing]: ../../std/ops/trait.Deref.html
6890//! [`Box`]: struct.Box.html
You can’t perform that action at this time.
0 commit comments