diff options
| author | Matthias Einwag <matthias.einwag@live.com> | 2019-02-06 22:56:33 -0800 |
|---|---|---|
| committer | Matthias Einwag <matthias.einwag@live.com> | 2019-02-06 22:56:33 -0800 |
| commit | a1c4cf6889f69dc335a3f0b42b29e4d9a081005d (patch) | |
| tree | 41f0c683d9f7adea20139205b076677ad37323ef /src/libcore/task | |
| parent | 8e7ef03141c40e34bd740bfe521b656387af9d56 (diff) | |
| download | rust-a1c4cf6889f69dc335a3f0b42b29e4d9a081005d.tar.gz rust-a1c4cf6889f69dc335a3f0b42b29e4d9a081005d.zip | |
Change RawWaker constructor to const fn
Diffstat (limited to 'src/libcore/task')
| -rw-r--r-- | src/libcore/task/wake.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index a877e033bc6..21f0a8cea41 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -19,9 +19,29 @@ pub struct RawWaker { /// that is associated with the task. /// The value of this field gets passed to all functions that are part of /// the vtable as the first parameter. - pub data: *const (), + data: *const (), /// Virtual function pointer table that customizes the behavior of this waker. - pub vtable: &'static RawWakerVTable, + vtable: &'static RawWakerVTable, +} + +impl RawWaker { + /// Creates a new `RawWaker` from the provided `data` pointer and `vtable`. + /// + /// The `data` pointer can be used to store arbitrary data as required + /// by the executor. This could be e.g. a type-erased pointer to an `Arc` + /// that is associated with the task. + /// The value of this poiner will get passed to all functions that are part + /// of the `vtable` as the first parameter. + /// + /// The `vtable` customizes the behavior of a `Waker` which gets created + /// from a `RawWaker`. For each operation on the `Waker`, the associated + /// function in the `vtable` of the underlying `RawWaker` will be called. + pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker { + RawWaker { + data, + vtable, + } + } } /// A virtual function pointer table (vtable) that specifies the behavior @@ -102,8 +122,8 @@ impl Waker { /// Creates a new `Waker` from [`RawWaker`]. /// /// The behavior of the returned `Waker` is undefined if the contract defined - /// in [RawWaker]'s documentation is not upheld. Therefore this method is - /// unsafe. + /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld. + /// Therefore this method is unsafe. pub unsafe fn new_unchecked(waker: RawWaker) -> Waker { Waker { waker, |
