2021-12-12 09:55:41 +00:00
|
|
|
use std::ptr;
|
|
|
|
use std::task::{RawWaker, RawWakerVTable, Waker};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_waker_getters() {
|
2022-06-27 15:09:53 +00:00
|
|
|
let raw_waker = RawWaker::new(ptr::invalid_mut(42usize), &WAKER_VTABLE);
|
2021-12-12 09:55:41 +00:00
|
|
|
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 15:09:53 +00:00
|
|
|
|data| RawWaker::new(ptr::invalid_mut(data as usize + 1), &WAKER_VTABLE),
|
2021-12-12 09:55:41 +00:00
|
|
|
|_| {},
|
|
|
|
|_| {},
|
|
|
|
|_| {},
|
|
|
|
);
|