Open
Description
This question is inspired by the slice_dst crate (cc @CAD97)
Is it valid, given a #[repr(C)]
struct with a trailing slice field, to cast a slice fat pointer to a fat pointer to that struct? If so, is it guaranteed that the slice length will be retained as expected? Concretely:
#[repr(C)]
struct Foo {
bar: u8,
baz: [u16],
}
fn create_foo_ptr(base: *const u8, elems: usize) -> *const Foo {
let slice_ptr = std::ptr::slice_from_raw_parts(base as *const u16, elems);
slice_ptr as *const Foo // <-- Will this produce a `*const Foo` with length `elems` for the `baz` field?
}
Metadata
Metadata
Assignees
Labels
No labels