@@ -263,13 +263,12 @@ Rust code:
263
263
264
264
~~~~no_run
265
265
266
- #[repr(C)]
267
266
struct RustObject {
268
267
a: i32,
269
268
// other members
270
269
}
271
270
272
- extern "C" fn callback(target: *mut RustObject, a:i32) {
271
+ extern fn callback(target: *mut RustObject, a:i32) {
273
272
println!("I'm called from C with value {0}", a);
274
273
unsafe {
275
274
// Update the value in RustObject with the value received from the callback
@@ -507,16 +506,16 @@ to define a block for all windows systems, not just x86 ones.
507
506
508
507
# Interoperability with foreign code
509
508
510
- Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C
511
- only if the `#[repr(C) ]` attribute is applied to it. `#[repr(C, packed)]` can be used to lay out
512
- struct members without padding. `#[repr(C)]` can also be applied to an enum.
509
+ Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C.
510
+ A `#[packed ]` attribute is available, which will lay out the struct members without padding.
511
+ However, there are currently no guarantees about the layout of an ` enum` .
513
512
514
- Rust's owned boxes (`Box<T>`) use non-nullable pointers as handles which point to the contained
513
+ Rust's owned and managed boxes use non-nullable pointers as handles which point to the contained
515
514
object. However, they should not be manually created because they are managed by internal
516
- allocators. References can safely be assumed to be non-nullable pointers directly to the type.
517
- However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so prefer
518
- using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions about
519
- them.
515
+ allocators. References can safely be assumed to be non-nullable pointers directly to the
516
+ type. However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so
517
+ prefer using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions
518
+ about them.
520
519
521
520
Vectors and strings share the same basic memory layout, and utilities are available in the `vec` and
522
521
`str` modules for working with C APIs. However, strings are not terminated with `\0`. If you need a
0 commit comments