feat: add main5
This commit is contained in:
@@ -2,6 +2,7 @@ mod main_1;
|
||||
mod main_2;
|
||||
mod main_3;
|
||||
mod main_4;
|
||||
mod main_5;
|
||||
|
||||
fn main() {
|
||||
println!("{}", "-".repeat(88));
|
||||
@@ -12,4 +13,6 @@ fn main() {
|
||||
main_3::run_main();
|
||||
println!("{}", "-".repeat(88));
|
||||
main_4::run_main();
|
||||
println!("{}", "-".repeat(88));
|
||||
main_5::run_main();
|
||||
}
|
||||
24
__ffi/c_layout/src/main_5.rs
Normal file
24
__ffi/c_layout/src/main_5.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::AsBytes;
|
||||
// use zerocopy::Unaligned;
|
||||
use zerocopy::LayoutVerified;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(FromBytes, AsBytes, Debug)]
|
||||
#[repr(C)]
|
||||
struct Header {
|
||||
name: [u8; 4],
|
||||
size: u32,
|
||||
reserved: u64,
|
||||
}
|
||||
|
||||
pub fn run_main() {
|
||||
let h = Header {
|
||||
name: [1,2,3,4],
|
||||
size: 0xabcdef,
|
||||
reserved: 0x0123456789abcdef,
|
||||
};
|
||||
println!("{:?}", h.as_bytes());
|
||||
let h2: Option<LayoutVerified<&[u8], [Header]>> = LayoutVerified::new_slice(h.as_bytes());
|
||||
println!("{:?}", h2.unwrap().deref()[0]);
|
||||
}
|
||||
Reference in New Issue
Block a user