Skip to content

Commit d8026d7

Browse files
committed
tests: add zeroing
1 parent 83a8869 commit d8026d7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/zeroing.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::{marker::PhantomPinned, ptr::addr_of_mut};
2+
3+
use pinned_init::*;
4+
5+
const MARKS: usize = 64;
6+
7+
#[pin_data]
8+
#[derive(Zeroable)]
9+
pub struct Foo {
10+
buf: [u8; 1024 * 1024],
11+
marks: [*mut u8; MARKS],
12+
pos: usize,
13+
#[pin]
14+
_pin: PhantomPinned,
15+
}
16+
17+
impl Foo {
18+
pub fn new() -> impl PinInit<Self> {
19+
pin_init!(&this in Self {
20+
marks: {
21+
let ptr = this.as_ptr();
22+
let ptr = unsafe { addr_of_mut!((*ptr).buf)}.cast::<u8>();
23+
[ptr; MARKS]},
24+
..Zeroable::zeroed()
25+
})
26+
}
27+
}
28+
29+
#[test]
30+
fn test() {
31+
let _ = Box::pin_init(Foo::new()).unwrap();
32+
}

0 commit comments

Comments
 (0)