Rollup merge of #129919 - kevinmehall:waker-getters, r=dtolnay · patricklam/verify-rust-std@181dc26 (original) (raw)

`@@ -60,22 +60,6 @@ impl RawWaker {

`

60

60

`RawWaker { data, vtable }

`

61

61

`}

`

62

62

``

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

``

-

79

63

`#[unstable(feature = "noop_waker", issue = "98286")]

`

80

64

`const NOOP: RawWaker = {

`

81

65

`const VTABLE: RawWakerVTable = RawWakerVTable::new(

`

`@@ -509,6 +493,37 @@ impl Waker {

`

509

493

` a_data == b_data && ptr::eq(a_vtable, b_vtable)

`

510

494

`}

`

511

495

``

``

496

`` +

/// Creates a new Waker from the provided data pointer and vtable.

``

``

497

`+

///

`

``

498

`` +

/// The data pointer can be used to store arbitrary data as required

``

``

499

`` +

/// by the executor. This could be e.g. a type-erased pointer to an Arc

``

``

500

`+

/// that is associated with the task.

`

``

501

`+

/// The value of this pointer will get passed to all functions that are part

`

``

502

`` +

/// of the vtable as the first parameter.

``

``

503

`+

///

`

``

504

`` +

/// It is important to consider that the data pointer must point to a

``

``

505

`` +

/// thread safe type such as an Arc.

``

``

506

`+

///

`

``

507

`` +

/// The vtable customizes the behavior of a Waker. For each operation

``

``

508

`` +

/// on the Waker, the associated function in the vtable will be called.

``

``

509

`+

///

`

``

510

`+

/// # Safety

`

``

511

`+

///

`

``

512

`` +

/// The behavior of the returned Waker is undefined if the contract defined

``

``

513

`` +

/// in [RawWakerVTable]'s documentation is not upheld.

``

``

514

`+

///

`

``

515

`` +

/// (Authors wishing to avoid unsafe code may implement the [Wake] trait instead, at the

``

``

516

`+

/// cost of a required heap allocation.)

`

``

517

`+

///

`

``

518

`` +

/// [Wake]: ../../alloc/task/trait.Wake.html

``

``

519

`+

#[inline]

`

``

520

`+

#[must_use]

`

``

521

`+

#[stable(feature = "waker_getters", since = "CURRENT_RUSTC_VERSION")]

`

``

522

`+

#[rustc_const_stable(feature = "waker_getters", since = "CURRENT_RUSTC_VERSION")]

`

``

523

`+

pub const unsafe fn new(data: *const (), vtable: &'static RawWakerVTable) -> Self {

`

``

524

`+

Waker { waker: RawWaker { data, vtable } }

`

``

525

`+

}

`

``

526

+

512

527

`` /// Creates a new Waker from [RawWaker].

``

513

528

`///

`

514

529

`/// # Safety

`

`@@ -565,12 +580,20 @@ impl Waker {

`

565

580

`WAKER

`

566

581

`}

`

567

582

``

568

``

`` -

/// Gets a reference to the underlying [RawWaker].

``

``

583

`` +

/// Gets the data pointer used to create this Waker.

``

569

584

`#[inline]

`

570

585

`#[must_use]

`

571

``

`-

#[unstable(feature = "waker_getters", issue = "96992")]

`

572

``

`-

pub fn as_raw(&self) -> &RawWaker {

`

573

``

`-

&self.waker

`

``

586

`+

#[stable(feature = "waker_getters", since = "CURRENT_RUSTC_VERSION")]

`

``

587

`+

pub fn data(&self) -> *const () {

`

``

588

`+

self.waker.data

`

``

589

`+

}

`

``

590

+

``

591

`` +

/// Gets the vtable pointer used to create this Waker.

``

``

592

`+

#[inline]

`

``

593

`+

#[must_use]

`

``

594

`+

#[stable(feature = "waker_getters", since = "CURRENT_RUSTC_VERSION")]

`

``

595

`+

pub fn vtable(&self) -> &'static RawWakerVTable {

`

``

596

`+

self.waker.vtable

`

574

597

`}

`

575

598

`}

`

576

599

``

`@@ -778,6 +801,30 @@ impl LocalWaker {

`

778

801

` a_data == b_data && ptr::eq(a_vtable, b_vtable)

`

779

802

`}

`

780

803

``

``

804

`` +

/// Creates a new LocalWaker from the provided data pointer and vtable.

``

``

805

`+

///

`

``

806

`` +

/// The data pointer can be used to store arbitrary data as required

``

``

807

`` +

/// by the executor. This could be e.g. a type-erased pointer to an Arc

``

``

808

`+

/// that is associated with the task.

`

``

809

`+

/// The value of this pointer will get passed to all functions that are part

`

``

810

`` +

/// of the vtable as the first parameter.

``

``

811

`+

///

`

``

812

`` +

/// The vtable customizes the behavior of a LocalWaker. For each

``

``

813

`` +

/// operation on the LocalWaker, the associated function in the vtable

``

``

814

`+

/// will be called.

`

``

815

`+

///

`

``

816

`+

/// # Safety

`

``

817

`+

///

`

``

818

`` +

/// The behavior of the returned Waker is undefined if the contract defined

``

``

819

`` +

/// in [RawWakerVTable]'s documentation is not upheld.

``

``

820

`+

///

`

``

821

`+

#[inline]

`

``

822

`+

#[must_use]

`

``

823

`+

#[unstable(feature = "local_waker", issue = "118959")]

`

``

824

`+

pub const unsafe fn new(data: *const (), vtable: &'static RawWakerVTable) -> Self {

`

``

825

`+

LocalWaker { waker: RawWaker { data, vtable } }

`

``

826

`+

}

`

``

827

+

781

828

`` /// Creates a new LocalWaker from [RawWaker].

``

782

829

`///

`

783

830

`` /// The behavior of the returned LocalWaker is undefined if the contract defined

``

`@@ -831,12 +878,20 @@ impl LocalWaker {

`

831

878

`WAKER

`

832

879

`}

`

833

880

``

834

``

`` -

/// Gets a reference to the underlying [RawWaker].

``

``

881

`` +

/// Gets the data pointer used to create this LocalWaker.

``

835

882

`#[inline]

`

836

883

`#[must_use]

`

837

``

`-

#[unstable(feature = "waker_getters", issue = "96992")]

`

838

``

`-

pub fn as_raw(&self) -> &RawWaker {

`

839

``

`-

&self.waker

`

``

884

`+

#[unstable(feature = "local_waker", issue = "118959")]

`

``

885

`+

pub fn data(&self) -> *const () {

`

``

886

`+

self.waker.data

`

``

887

`+

}

`

``

888

+

``

889

`` +

/// Gets the vtable pointer used to create this LocalWaker.

``

``

890

`+

#[inline]

`

``

891

`+

#[must_use]

`

``

892

`+

#[unstable(feature = "local_waker", issue = "118959")]

`

``

893

`+

pub fn vtable(&self) -> &'static RawWakerVTable {

`

``

894

`+

self.waker.vtable

`

840

895

`}

`

841

896

`}

`

842

897

`#[unstable(feature = "local_waker", issue = "118959")]

`