rust/src/libstd
Without Boats 06ede350c2 Add Wake trait for safe construction of Wakers.
Currently, constructing a waker requires calling the unsafe
`Waker::from_raw` API. This API requires the user to manually construct
a vtable for the waker themself - which is both cumbersome and very
error prone. This API would provide an ergonomic, straightforward and
guaranteed memory-safe way of constructing a waker.

It has been our longstanding intention that the `Waker` type essentially
function as an `Arc<dyn Wake>`, with a `Wake` trait as defined here. Two
considerations prevented the original API from being shipped as simply
an `Arc<dyn Wake>`:

- We want to support futures on embedded systems, which may not have an
  allocator, and in optimized executors for which this API may not be
  best-suited. Therefore, we have always explicitly supported the
  maximally-flexible (but also memory-unsafe) `RawWaker` API, and
  `Waker` has always lived in libcore.
- Because `Waker` lives in libcore and `Arc` lives in liballoc, it has
  not been feasible to provide a constructor for `Waker` from `Arc<dyn
  Wake>`.

Therefore, the Wake trait was left out of the initial version of the
task waker API.

However, as Rust 1.41, it is possible under the more flexible orphan
rules to implement `From<Arc<W>> for Waker where W: Wake` in liballoc.
Therefore, we can now define this constructor even though `Waker` lives
in libcore.

This PR adds these APIs:

- A `Wake` trait, which contains two methods
    - A required method `wake`, which is called by `Waker::wake`
    - A provided method `wake_by_ref`, which is called by
      `Waker::wake_by_ref` and which implementors can override if they
      can optimize this use case.
- An implementation of `From<Arc<W>> for Waker where W: Wake + Send +
  Sync + 'static`
- A similar implementation of `From<Arc<W>> for RawWaker`.
2020-03-23 15:44:58 +01:00
..
benches Format libstd with rustfmt 2019-11-29 18:43:27 -08:00
collections Don't redundantly repeat field names (clippy::redundant_field_names) 2020-03-06 19:42:18 +01:00
ffi Rollup merge of #64069 - danielhenrymantilla:feature/cstring_from_vec_of_nonzerou8, r=KodrAus 2020-02-15 09:45:38 +01:00
io Rollup merge of #70232 - adrian5:patch-1, r=Dylan-DPC 2020-03-21 22:56:30 +01:00
net For issue 53957: revise unit tests to focus on underlying bug of 23076. 2020-03-20 13:56:25 -04:00
os fix various typos 2020-03-06 15:19:31 +01:00
prelude builtin_macros: Add attribute macro #[cfg_accessible(path)] 2020-03-10 01:02:13 +03:00
sync Fix "since" field for Once::is_complete's #[stable] attribute 2020-03-15 10:19:26 +01:00
sys Rollup merge of #70207 - hatoo:macos-getentropy, r=dtolnay 2020-03-23 04:26:07 +01:00
sys_common Rollup merge of #69955 - alexcrichton:stderr-infallible, r=sfackler 2020-03-21 13:06:38 +01:00
tests stdarch: update submodule. 2020-02-01 22:04:18 -05:00
thread Return NonZeroU64 from ThreadId::as_u64. 2020-03-21 19:48:23 +01:00
alloc.rs Allow ZSTs in AllocRef 2020-03-08 11:01:12 +01:00
ascii.rs Format libstd with rustfmt 2019-11-29 18:43:27 -08:00
backtrace.rs remove redundant returns (clippy::needless_return) 2020-03-20 20:23:03 +01:00
build.rs remove dependency from libhermit 2019-11-25 08:59:23 +01:00
Cargo.toml Bump version to backtrace without the header 2020-02-10 14:20:21 -08:00
env.rs doc: Add quote to .init_array 2020-03-19 17:35:28 +07:00
error.rs Fix deprecated Error.description() usage in docs 2020-03-21 12:33:52 +02:00
f32.rs Add notice about using new consts in new code on float modules 2020-02-12 20:20:56 +01:00
f64.rs Add notice about using new consts in new code on float modules 2020-02-12 20:20:56 +01:00
fs.rs Fix missing ` in doc for File::with_options 2020-03-06 14:27:09 +00:00
future.rs Add futures scaffolding to libcore 2020-03-17 22:17:31 +01:00
keyword_docs.rs Rollup merge of #67749 - gilescope:keyword-in, r=Dylan-DPC 2020-03-18 18:03:31 +01:00
lib.rs Add Wake trait for safe construction of Wakers. 2020-03-23 15:44:58 +01:00
macros.rs Update macros.rs: fix documentation typo. 2020-03-04 14:18:31 -05:00
memchr.rs libstd => 2018 2019-02-28 04:06:15 +09:00
num.rs Format libstd with rustfmt 2019-11-29 18:43:27 -08:00
panic.rs Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
panicking.rs Auto merge of #70010 - Amanieu:fix-opt-catch, r=Mark-Simulacrum 2020-03-16 08:08:51 +00:00
path.rs remove unneeded .as_ref() calls. 2020-02-29 02:16:04 +01:00
primitive_docs.rs Add notice about using new consts in new code on float modules 2020-02-12 20:20:56 +01:00
process.rs Format libstd with rustfmt 2019-11-29 18:43:27 -08:00
rt.rs Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
time.rs correct comment to match behavior 2020-02-29 08:40:09 -05:00