Move the data and vtable methods from RawWaker to Waker

Per the `waker_getters` FCP:
https://github.com/rust-lang/rust/issues/96992#issuecomment-1941998046
This commit is contained in:
Kevin Mehall 2024-09-02 17:38:51 -06:00
parent bd53aa3bf7
commit 8d3e5fa0ae
2 changed files with 27 additions and 28 deletions

View file

@ -60,22 +60,6 @@ pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker {
RawWaker { data, vtable }
}
/// Gets the `data` pointer used to create this `RawWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn data(&self) -> *const () {
self.data
}
/// Gets the `vtable` pointer used to create this `RawWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.vtable
}
#[unstable(feature = "noop_waker", issue = "98286")]
const NOOP: RawWaker = {
const VTABLE: RawWakerVTable = RawWakerVTable::new(
@ -565,12 +549,20 @@ pub const fn noop() -> &'static Waker {
WAKER
}
/// Gets a reference to the underlying [`RawWaker`].
/// Gets the `data` pointer used to create this `Waker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn as_raw(&self) -> &RawWaker {
&self.waker
pub fn data(&self) -> *const () {
self.waker.data
}
/// Gets the `vtable` pointer used to create this `Waker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.waker.vtable
}
}
@ -831,12 +823,20 @@ pub const fn noop() -> &'static LocalWaker {
WAKER
}
/// Gets a reference to the underlying [`RawWaker`].
/// Gets the `data` pointer used to create this `LocalWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn as_raw(&self) -> &RawWaker {
&self.waker
pub fn data(&self) -> *const () {
self.waker.data
}
/// Gets the `vtable` pointer used to create this `LocalWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "96992")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.waker.vtable
}
}
#[unstable(feature = "local_waker", issue = "118959")]

View file

@ -4,14 +4,13 @@
#[test]
fn test_waker_getters() {
let raw_waker = RawWaker::new(ptr::without_provenance_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) };
assert_eq!(waker.data() as usize, 42);
assert!(ptr::eq(waker.vtable(), &WAKER_VTABLE));
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));
assert_eq!(waker2.data() as usize, 43);
assert!(ptr::eq(waker2.vtable(), &WAKER_VTABLE));
}
static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(