rust/library/core/tests/waker.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
691 B
Rust
Raw Normal View History

use std::ptr;
use std::task::{RawWaker, RawWakerVTable, Waker};
#[test]
fn test_waker_getters() {
2022-06-27 10:09:53 -05:00
let raw_waker = RawWaker::new(ptr::invalid_mut(42usize), &WAKER_VTABLE);
assert_eq!(raw_waker.data() as usize, 42);
assert!(ptr::eq(raw_waker.vtable(), &WAKER_VTABLE));
let waker = unsafe { Waker::from_raw(raw_waker) };
let waker2 = waker.clone();
let raw_waker2 = waker2.as_raw();
assert_eq!(raw_waker2.data() as usize, 43);
assert!(ptr::eq(raw_waker2.vtable(), &WAKER_VTABLE));
}
static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
2022-06-27 10:09:53 -05:00
|data| RawWaker::new(ptr::invalid_mut(data as usize + 1), &WAKER_VTABLE),
|_| {},
|_| {},
|_| {},
);