Open
Description
Hello, that's me again
What is the best way to safely pack/unpack a bilge struct to/from a byte slice ?
I have found the following in the readme, but not exactly what I am looking for:
#[bitsize(N)]
struct MyStruct {}
// safe way to cast from/to integers
let v = MyStruct::new(0_uN)
let n = v.value()
// unsafe way to cast from/to byte array
let v = unsafe{ std::mem::transmute<&[u8; N], &MyStruct>() }
let a = unsafe{ std::mem::transmute<&MyStruct, &[u8; N]>() }
Did I missed something for safely doing the same with byte slices or byte arrays ?
Metadata
Assignees
Labels
No labels
Activity