Skip to content

Commit

Permalink
tests: add zeroing
Browse files Browse the repository at this point in the history
  • Loading branch information
y86-dev committed Apr 11, 2024
1 parent d24fd22 commit e72c8f8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/zeroing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::{marker::PhantomPinned, ptr::addr_of_mut};

use pinned_init::*;

const MARKS: usize = 64;

#[pin_data]
#[derive(Zeroable)]
pub struct Foo {
buf: [u8; 1024 * 1024],
marks: [*mut u8; MARKS],
pos: usize,
#[pin]
_pin: PhantomPinned,
}

impl Foo {
pub fn new() -> impl PinInit<Self> {
pin_init!(&this in Self {
marks: {
let ptr = this.as_ptr();
let ptr = unsafe { addr_of_mut!((*ptr).buf)}.cast::<u8>();
[ptr; MARKS]},
..Zeroable::zeroed()
})
}
}

#[test]
fn test() {
let _ = Box::pin_init(Foo::new()).unwrap();
}

0 comments on commit e72c8f8

Please sign in to comment.