File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 63
63
//! T` obtained from `Box::<T>::into_raw` may be deallocated using the
64
64
//! [`Global`] allocator with `Layout::for_value(&*value)`.
65
65
//!
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
+ //! ```
66
88
//!
67
89
//! [dereferencing]: ../../std/ops/trait.Deref.html
68
90
//! [`Box`]: struct.Box.html
You can’t perform that action at this time.
0 commit comments