Skip to content

Commit 8d3e5fa

Browse files
committed
Move the data and vtable methods from RawWaker to Waker
Per the `waker_getters` FCP: #96992 (comment)
1 parent bd53aa3 commit 8d3e5fa

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

Diff for: library/core/src/task/wake.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,6 @@ impl RawWaker {
6060
RawWaker { data, vtable }
6161
}
6262

63-
/// Gets the `data` pointer used to create this `RawWaker`.
64-
#[inline]
65-
#[must_use]
66-
#[unstable(feature = "waker_getters", issue = "96992")]
67-
pub fn data(&self) -> *const () {
68-
self.data
69-
}
70-
71-
/// Gets the `vtable` pointer used to create this `RawWaker`.
72-
#[inline]
73-
#[must_use]
74-
#[unstable(feature = "waker_getters", issue = "96992")]
75-
pub fn vtable(&self) -> &'static RawWakerVTable {
76-
self.vtable
77-
}
78-
7963
#[unstable(feature = "noop_waker", issue = "98286")]
8064
const NOOP: RawWaker = {
8165
const VTABLE: RawWakerVTable = RawWakerVTable::new(
@@ -565,12 +549,20 @@ impl Waker {
565549
WAKER
566550
}
567551

568-
/// Gets a reference to the underlying [`RawWaker`].
552+
/// Gets the `data` pointer used to create this `Waker`.
569553
#[inline]
570554
#[must_use]
571555
#[unstable(feature = "waker_getters", issue = "96992")]
572-
pub fn as_raw(&self) -> &RawWaker {
573-
&self.waker
556+
pub fn data(&self) -> *const () {
557+
self.waker.data
558+
}
559+
560+
/// Gets the `vtable` pointer used to create this `Waker`.
561+
#[inline]
562+
#[must_use]
563+
#[unstable(feature = "waker_getters", issue = "96992")]
564+
pub fn vtable(&self) -> &'static RawWakerVTable {
565+
self.waker.vtable
574566
}
575567
}
576568

@@ -831,12 +823,20 @@ impl LocalWaker {
831823
WAKER
832824
}
833825

834-
/// Gets a reference to the underlying [`RawWaker`].
826+
/// Gets the `data` pointer used to create this `LocalWaker`.
835827
#[inline]
836828
#[must_use]
837829
#[unstable(feature = "waker_getters", issue = "96992")]
838-
pub fn as_raw(&self) -> &RawWaker {
839-
&self.waker
830+
pub fn data(&self) -> *const () {
831+
self.waker.data
832+
}
833+
834+
/// Gets the `vtable` pointer used to create this `LocalWaker`.
835+
#[inline]
836+
#[must_use]
837+
#[unstable(feature = "waker_getters", issue = "96992")]
838+
pub fn vtable(&self) -> &'static RawWakerVTable {
839+
self.waker.vtable
840840
}
841841
}
842842
#[unstable(feature = "local_waker", issue = "118959")]

Diff for: library/core/tests/waker.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use std::task::{RawWaker, RawWakerVTable, Waker};
44
#[test]
55
fn test_waker_getters() {
66
let raw_waker = RawWaker::new(ptr::without_provenance_mut(42usize), &WAKER_VTABLE);
7-
assert_eq!(raw_waker.data() as usize, 42);
8-
assert!(ptr::eq(raw_waker.vtable(), &WAKER_VTABLE));
9-
107
let waker = unsafe { Waker::from_raw(raw_waker) };
8+
assert_eq!(waker.data() as usize, 42);
9+
assert!(ptr::eq(waker.vtable(), &WAKER_VTABLE));
10+
1111
let waker2 = waker.clone();
12-
let raw_waker2 = waker2.as_raw();
13-
assert_eq!(raw_waker2.data() as usize, 43);
14-
assert!(ptr::eq(raw_waker2.vtable(), &WAKER_VTABLE));
12+
assert_eq!(waker2.data() as usize, 43);
13+
assert!(ptr::eq(waker2.vtable(), &WAKER_VTABLE));
1514
}
1615

1716
static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(

0 commit comments

Comments
 (0)