pub struct Discard<F>(pub F);Expand description
Timer is defined once, in hclient-core: the portable core needs it
for timeouts and backoff. This is just a re-export.
Discard comes with it: Timer::Sleep is a named associated type, and
a runtime whose native timer resolves to something other than () — as
async_io::Timer does — needs the adapter to satisfy it. Re-exported
here so a runtime crate does not have to depend on hclient-core
directly just to name one wrapper.
Adapts a future that resolves to something into one that resolves to
(), for use as a Timer::Sleep.
This is not redundant, and it is not a mistake. Two of this
project’s clocks have a native timer whose Output is not ():
async_io::Timer resolves to the std::time::Instant at which it
fired, and hclient-fetch’s SendJsFuture resolves to
Result<JsValue, JsValue>. While Timer::sleep was an RPITIT both
were discarded invisibly inside an async block; with a named
associated type the discard has to be written down, and this is where
it is written down once instead of twice.
F: Unpin rather than a pin projection: every timer this wraps is
Unpin already, and this workspace forbids unsafe, so the safe
projection is the only one available and the bound is honest about it.
Tuple Fields§
§0: F