Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"deed0a442b53d578f397083a5a1034a6bc546e948957218efe0f027d32a65769","Cargo.lock":"8eb703a4cb18ec5224283c75bc06d2102f8359a84d4927737b58f6c0f7bfa8c4","Cargo.toml":"43218a6e46a95142ade2400a01937357a4d220dbf467462739b578c43a09848a","FEATURES.md":"2904922c4e7f09ac4105c99e931594467804c80deb1f5eaec3b296386c332278","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","LICENSE-THIRD-PARTY":"6226d0632e2e1a80c23597e964da9812ae193c535fe058154afb034e94167aa5","README.md":"0242ae3d8e434dbafb916997adfc8fea1b7c49fa9b2de25f515a69c523e8bba7","src/future.rs":"23b6f79a4366860dbfafb38308147f923196766facc9c9b1a436f1331b94f8e9","src/io.rs":"fb5301c11bf40b2b9508942043671ec12cb9c0c0e13adbe2283980d0a7cd852e","src/lib.rs":"277b557fe7e7835cceb2d856c8e6adf20be8d6602b65ce0feecea38bd6d384d6","src/prelude.rs":"ab0ec9c549e9104c84ae64dfba03d4078702a0897c5ac3e15770dd692c6b23e3","src/stream.rs":"87f6fb8404dbd7114a8973f20798eaa022a8be3c30a307a0fa33a3bd1de56df5"},"package":"f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"}

212
vendor/futures-lite/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,212 @@
# Version 2.6.1
- Fix docs for `once_future` and `stop_after_future`. (#131)
# Version 2.6.0
- Add `Stream::map_while()` combinator. (#116)
- Add list of excluded features to crate documentation. (#112)
- Update docs for `AsyncRead::read_exact` (#121)
# Version 2.5.0
- Remove `Unpin` bound from the `Lines` I/O adapter. (#113)
# Version 2.4.0
- Add a "fuse" method that makes it so a `Future` returns `Poll::Pending`
forever after it returns `Poll::Pending` once. (#101)
- Add a "stop_after_future" function that allows for running a `Stream` until a
`Future` completes. (#103)
- Make it so `Zip`/`TryZip` drop completed futures. (#106)
# Version 2.3.0
- Add `StreamExt::drain` for draining objects from a `Stream` without waiting (#70).
# Version 2.2.0
- Relax `Unpin` bounds on `io::copy`. (#87)
- Implement `size_hint` for `stream::Filter`. (#88)
- Relax MSRV to 1.60. (#90)
# Version 2.1.0
- Make it so `read_line` and other futures use a naive implementation of byte
searching unless the `memchr` feature is enabled. This prevents needing to
compile the `memchr` crate unless it is desired. (#77)
# Version 2.0.1
- Remove dependency on the `waker-fn` crate. (#81)
# Version 2.0.0
- **Breaking:** Expose `future::{ready, pending}` from `core` instead of defining
our own. (#73)
- **Breaking:** The `TryZip` and `Zip` combinators are modified to have a cleaner
API, where generic constraints are not necessary on the structure itself at the
cost of additional generics. (#74)
- Add a way to use racey futures on `no_std` by providing your own seed. (#75)
# Version 1.13.0
- Unbind Debug implementations of BufReader and BufWriter. (#49)
- Add the once_future() combinator. (#59)
- Add a combinator for temporarily using an AsyncRead/AsyncWrite as Read/Write. (#62)
- Implement more methods for stream::BlockOn. (#68)
# Version 1.12.0
- Implement `BufRead` for `BlockOn`
# Version 1.11.3
- Update `pin-project-lite`.
# Version 1.11.2
- Improve docs for `ready!`.
# Version 1.11.1
- Fix some typos.
# Version 1.11.0
- Add the new `prelude` module.
- Deprecate trait re-exports in the root module.
# Version 1.10.1
- Fix compilation errors with Rust 1.42.0 and 1.45.2
# Version 1.10.0
- Add `io::split()`.
# Version 1.9.0
- Add `FutureExt::poll()`.
- Add `StreamExt::poll_next()`.
- Add `AsyncBufReadExt::fill_buf()`.
- Add `AsyncBufReadExt::consume()`.
# Version 1.8.0
- Add `BoxedReader` and `BoxedWriter`.
# Version 1.7.0
- Implement `AsyncRead` for `Bytes`.
- Add `StreamExt::then()`.
# Version 1.6.0
- Add `FutureExt::catch_unwind()`.
# Version 1.5.0
- Add `stream::race()` and `StreamExt::race()`.
# Version 1.4.0
- Add `alloc` Cargo feature.
# Version 1.3.0
- Add `future::or()`.
- Add `FutureExt::race()`.
- Disable `waker-fn` dependency on `#![no_std]` targets.
# Version 1.2.0
- Fix compilation errors on `#![no_std]` systems.
- Add `StreamExt::try_next()`.
- Add `StreamExt::partition()`.
- Add `StreamExt::for_each()`.
- Add `StreamExt::try_for_each()`.
- Add `StreamExt::zip()`.
- Add `StreamExt::unzip()`.
- Add `StreamExt::nth()`.
- Add `StreamExt::last()`.
- Add `StreamExt::find()`.
- Add `StreamExt::find_map()`.
- Add `StreamExt::position()`.
- Add `StreamExt::all()`.
- Add `StreamExt::any()`.
- Add `StreamExt::scan()`.
- Add `StreamExt::flat_map()`.
- Add `StreamExt::flatten()`.
- Add `StreamExt::skip()`.
- Add `StreamExt::skip_while()`.
# Version 1.1.0
- Add `StreamExt::take()`.
- Add `StreamExt::take_while()`.
- Add `StreamExt::step_by()`.
- Add `StreamExt::fuse()`.
- Add `StreamExt::chain()`.
- Add `StreamExt::cloned()`.
- Add `StreamExt::copied()`.
- Add `StreamExt::cycle()`.
- Add `StreamExt::enumeraate()`.
- Add `StreamExt::inspect()`.
- Parametrize `FutureExt::boxed()` and `FutureExt::boxed_local()` over a lifetime.
- Parametrize `StreamExt::boxed()` and `StreamExt::boxed_local()` over a lifetime.
# Version 1.0.0
- Add `StreamExt::map()`.
- Add `StreamExt::count()`.
- Add `StreamExt::filter()`.
- Add `StreamExt::filter_map()`.
- Rename `future::join()` to `future::zip()`.
- Rename `future::try_join()` to `future::try_zip()`.
# Version 0.1.11
- Update `parking` to v2.0.0
# Version 0.1.10
- Add `AssertAsync`.
# Version 0.1.9
- Add `FutureExt::or()`.
- Put `#[must_use]` on all futures and streams.
# Version 0.1.8
- Fix lints about unsafe code.
# Version 0.1.7
- Add blocking APIs (`block_on()` and `BlockOn`).
# Version 0.1.6
- Add `boxed()`, `boxed_local()`, `Boxed`, and `BoxedLocal`.
# Version 0.1.5
- Add `fold()` and `try_fold()`.
# Version 0.1.4
- Add `future::race()`.
- Fix a bug in `BufReader`.
# Version 0.1.3
- Add `future::join()`, `future::try_join()`, and `AsyncWriteExt::close()`.
# Version 0.1.2
- Lots of new APIs.
# Version 0.1.1
- Initial version

74
vendor/futures-lite/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,74 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "futures-core"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-io"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
[[package]]
name = "futures-lite"
version = "2.6.1"
dependencies = [
"fastrand",
"futures-core",
"futures-io",
"memchr",
"parking",
"pin-project-lite",
"spin_on",
"waker-fn",
]
[[package]]
name = "memchr"
version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "parking"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
[[package]]
name = "pin-project-lite"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "spin_on"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "076e103ed41b9864aa838287efe5f4e3a7a0362dd00671ae62a212e5e4612da2"
dependencies = [
"pin-utils",
]
[[package]]
name = "waker-fn"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7"

90
vendor/futures-lite/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,90 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.60"
name = "futures-lite"
version = "2.6.1"
authors = [
"Stjepan Glavina <stjepang@gmail.com>",
"Contributors to futures-rs",
]
build = false
exclude = ["/.*"]
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Futures, streams, and async I/O combinators"
homepage = "https://github.com/smol-rs/futures-lite"
documentation = "https://docs.rs/futures-lite"
readme = "README.md"
keywords = [
"asynchronous",
"futures",
"async",
]
categories = [
"asynchronous",
"concurrency",
]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/smol-rs/futures-lite"
[features]
alloc = []
default = [
"race",
"std",
]
race = ["fastrand"]
std = [
"alloc",
"fastrand/std",
"futures-io",
"parking",
]
[lib]
name = "futures_lite"
path = "src/lib.rs"
[dependencies.fastrand]
version = "2.0.0"
optional = true
default-features = false
[dependencies.futures-core]
version = "0.3.5"
default-features = false
[dependencies.futures-io]
version = "0.3.5"
optional = true
[dependencies.memchr]
version = "2.3.3"
optional = true
[dependencies.parking]
version = "2.2.0"
optional = true
[dependencies.pin-project-lite]
version = "0.2.0"
[dev-dependencies.spin_on]
version = "0.1.0"
[dev-dependencies.waker-fn]
version = "1.0.0"

275
vendor/futures-lite/FEATURES.md vendored Normal file
View File

@@ -0,0 +1,275 @@
# Intentional Occlusions from `futures-lite`
[`futures-lite`] has an API that is deliberately smaller than the [`futures`]
crate. This allows it to compile significantly faster and have fewer
dependencies.
This fact does not mean that [`futures-lite`] is not open to new feature
requests. However it does mean that any proposed new features are subject to
scrutiny to determine whether or not they are truly necessary for this crate.
In many cases there are much simpler ways to implement these features, or they
would be a much better fit for an external crate.
This document aims to describe all intentional feature occlusions and provide
suggestions for how these features can be used in the context of
[`futures-lite`]. If you have a feature request that you believe does not fall
under any of the following occlusions, please open an issue on the
[official `futures-lite` bug tracker](https://github.com/smol-rs/futures-lite/issues).
## Simple Combinators
In general, anything that can be implemented in terms of `async`/`await` syntax
is not implemented in [`futures-lite`]. This is done to encourage the use of
modern `async`/`await` syntax rather than [`futures`] v1.0 combinator chaining.
As an example, take the [`map`] method in [`futures`]. It takes a future and
processes its output through a closure.
```rust
let my_future = async { 1 };
// Add one to the result of `my_future`.
let mapped_future = my_future.map(|x| x + 1);
assert_eq!(mapped_future.await, 2);
```
However, this does not need to be implemented in the form of a combinator. With
`async`/`await` syntax, you can simply `await` on `my_future` in an `async`
block, then process its output. The following code is equivalent to the above,
but doesn't use a combinator.
```rust
let my_future = async { 1 };
// Add one to the result of `my_future`.
let mapped_future = async move { my_future.await + 1 };
assert_eq!(mapped_future.await, 2);
```
By not implementing combinators that can be implemented in terms of `async`,
[`futures-lite`] has a significantly smaller API that still has roughly the
same amount of power as [`futures`].
As part of this policy, the [`TryFutureExt`] trait is not implemented. All of
its methods can be implemented by just using `async`/`await` combined with
other simpler future combinators. For instance, consider [`and_then`]:
```rust
let my_future = async { Ok(2) };
let and_then = my_future.and_then(|x| async move {
Ok(x + 1)
});
assert_eq!(and_then.await.unwrap(), 3);
```
This can be implemented with an `async` block and the normal `and_then`
combinator.
```rust
let my_future = async { Ok(2) };
let and_then = async move {
let x = my_future.await;
x.and_then(|x| x + 1)
};
assert_eq!(and_then.await.unwrap(), 3);
```
One drawback of this approach is that `async` blocks are not named types. So
if a trait (like [`Service`]) requires a named future type it cannot be
returned.
```rust
impl Service for MyService {
type Future = /* ??? */;
fn call(&mut self) -> Self::Future {
async { 1 + 1 }
}
}
```
One possible solution is to box the future and return a dynamic dispatch
object, but in many cases this adds non trivial overhead.
```rust
impl Service for MyService {
type Future = Pin<Box<dyn Future<Output = i32>>>;
fn call(&mut self) -> Self::Future {
async { 1 + 1 }.boxed_local()
}
}
```
This problem is expected to be resolved in the future, thanks to
[`async` fn in traits] and [TAIT]. At this point we would rather wait for these
better solutions than significantly expand [`futures-lite`]'s API. If this is a
deal breaker for you, [`futures`] is probably better for your use case.
## Asynchronous Closures
As a pattern, most combinators in [`futures-lite`] take regular closures rather
than `async` closures. For example:
```rust
// In `futures`, the `all` combinator takes a closure returning a future.
my_stream.all(|x| async move { x > 5 }).await;
// In `futures-lite`, the `all` combinator just takes a closure.
my_stream.all(|x| x > 5).await;
```
This strategy is taken for two primary reasons.
First of all, it is significantly simpler to implement. Since we don't need to
keep track of whether we are currently `poll`ing a future or not it makes the
combinators an order of magnitude easier to write.
Second of all it avoids the common [`futures`] wart of needing to pass trivial
values into `async move { ... }` or `future::ready(...)` for the vast
majority of operations.
For futures, combinators that would normally require `async` closures can
usually be implemented in terms of `async`/`await`. See the above section for
more information on that. For streams, the [`then`] combinator is one of the
few that actually takes an `async` closure, and can therefore be used to
implement operations that would normally need `async` closures.
```rust
// In `futures`.
my_stream.all(|x| my_async_fn(x)).await;
// In `futures-lite`, use `then` and pass the result to `all`.
my_stream.then(|x| my_async_fn(x)).all(|pass| pass).await;
```
## Higher-Order Concurrency
[`futures`] provides a number of primitives and combinators that allow for
polling a significant number of futures at once. Examples of this include
[`for_each_concurrent`] and [`FuturesUnordered`].
[`futures-lite`] provides simple primitives like [`race`] and [`zip`]. However
these don't really scale to handling more than two futures at once. It has
been proposed in the past to add deeper concurrency primitives to
[`futures-lite`]. However our current stance is that such primitives would
represent a significant uptick in complexity and thus is better suited to
other crates.
[`futures-concurrency`] provides a number of simple APIs for dealing with
fixed numbers of futures. For example, here is an example for waiting on
multiple futures to complete.
```rust
let (a, b, c) = /* assume these are all futures */;
// futures
let (x, y, z) = join!(a, b, c);
// futures-concurrency
use futures_concurrency::prelude::*;
let (x, y, z) = (a, b, c).join().await;
```
For large or variable numbers of futures it is recommended to use an executor
instead. [`smol`] provides both an [`Executor`] and a [`LocalExecutor`]
depending on the flavor of your program.
@notgull has a [blog post](https://notgull.net/futures-concurrency-in-smol/)
describing this in greater detail.
To explicitly answer a frequently asked question, the popular [`select`] macro
can be implemented by using simple `async`/`await` and a race combinator.
```rust
let (a, b, c) = /* assume these are all futures */;
// futures
let x = select! {
a_res = a => a_res + 1,
_ = b => 0,
c_res = c => c_res + 3,
};
// futures-concurrency
let x = (
async move { a.await + 1 },
async move { b.await; 0 },
async move { c.await + 3 }
).race().await;
```
## Sink Trait
[`futures`] offers a [`Sink`] trait that is in many ways the opposite of the
[`Stream`] trait. Rather than asynchronously producing values, the point of the
[`Sink`] is to asynchronously receive values.
[`futures-lite`] and the rest of [`smol`] intentionally does not support the
[`Sink`] trait. [`Sink`] is a relic from the old [`futures`] v0.1 days where
I/O was tied directly into the API. The `Error` subtype is wholly unnecessary
and makes the API significantly harder to use. In addition the multi-call
requirement makes the API harder to both use and implement. It increases the
complexity of any futures that use it significantly, and its API necessitates
that implementors have an internal buffer for objects.
In short, the ideal [`Sink`] API would be if it was replaced with this trait.
*Sidenote: [`Stream`], [`AsyncRead`] and [`AsyncWrite`] suffer from this same
problem to an extent. I think they could also be fixed by transforming their
`fn poll_[X]` functions into `async fn [X]` functions. However their APIs are
not broken to the point that [`Sink`]'s is.*
In order to avoid relying on a broken API, [`futures-lite`] does not import
[`Sink`] or expose any APIs that build upon [`Sink`]. Unfortunately some crates
make their only accessible API the [`Sink`] call. Ideally instead they would
just have an `async fn send()` function.
## Out-of-scope modules
[`futures`] provides several sets of tools that are out of scope for
[`futures-lite`]. Usually these are implemented in external crates, some of
which depend on [`futures-lite`] themselves. Here are examples of these
primitives:
- **Channels:** [`async-channel`] provides an asynchronous MPMC channel, while
[`oneshot`] provides an asynchronous oneshot channel.
- **Mutex:** [`async-lock`] provides asynchronous mutexes, alongside other
locking primitives.
- **Atomic Wakers:** [`atomic-waker`] provides standalone atomic wakers.
- **Executors:** [`async-executor`] provides [`Executor`] to replace
`ThreadPool` and [`LocalExecutor`] to replace `LocalPool`.
[`smol`]: https://crates.io/crates/smol
[`futures-lite`]: https://crates.io/crates/futures-lite
[`futures`]: https://crates.io/crates/futures
[`map`]: https://docs.rs/futures/latest/futures/future/trait.FutureExt.html#method.map
[`TryFutureExt`]: https://docs.rs/futures/latest/futures/future/trait.TryFutureExt.html
[`and_then`]: https://docs.rs/futures/latest/futures/future/trait.TryFutureExt.html#method.and_then
[`Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html
[`async` fn in traits]: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html
[TAIT]: https://rust-lang.github.io/impl-trait-initiative/explainer/tait.html
[`then`]: https://docs.rs/futures-lite/latest/futures_lite/stream/trait.StreamExt.html#method.then
[`FuturesUnordered`]: https://docs.rs/futures/latest/futures/stream/struct.FuturesUnordered.html
[`for_each_concurrent`]: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.for_each_concurrent
[`race`]: https://docs.rs/futures-lite/latest/futures_lite/future/fn.race.html
[`zip`]: https://docs.rs/futures-lite/latest/futures_lite/future/fn.zip.html
[`futures-concurrency`]: https://docs.rs/futures-concurrency/latest/futures_concurrency/
[`Executor`]: https://docs.rs/async-executor/latest/async_executor/struct.Executor.html
[`LocalExecutor`]: https://docs.rs/async-executor/latest/async_executor/struct.LocalExecutor.html
[`select`]: https://docs.rs/futures/latest/futures/macro.select.html
[`Sink`]: https://docs.rs/futures/latest/futures/sink/trait.Sink.html
[`Stream`]: https://docs.rs/futures-core/latest/futures_core/stream/trait.Stream.html
[`AsyncRead`]: https://docs.rs/futures-io/latest/futures_io/trait.AsyncRead.html
[`AsyncWrite`]: https://docs.rs/futures-io/latest/futures_io/trait.AsyncWrite.html
[`async-channel`]: https://crates.io/crates/async-channel
[`async-lock`]: https://crates.io/crates/async-lock
[`async-executor`]: https://crates.io/crates/async-executor
[`oneshot`]: https://crates.io/crates/oneshot
[`atomic-waker`]: https://crates.io/crates/atomic-waker

201
vendor/futures-lite/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

23
vendor/futures-lite/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

45
vendor/futures-lite/LICENSE-THIRD-PARTY vendored Normal file
View File

@@ -0,0 +1,45 @@
===============================================================================
Copyright (c) 2016 Alex Crichton
Copyright (c) 2017 The Tokio Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
===============================================================================
Copyright (c) 2016 Alex Crichton
Copyright (c) 2017 The Tokio Authors
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

51
vendor/futures-lite/README.md vendored Normal file
View File

@@ -0,0 +1,51 @@
# futures-lite
[![Build](https://github.com/smol-rs/futures-lite/workflows/Build%20and%20test/badge.svg)](
https://github.com/smol-rs/futures-lite/actions)
[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](
https://github.com/smol-rs/futures-lite)
[![Cargo](https://img.shields.io/crates/v/futures-lite.svg)](
https://crates.io/crates/futures-lite)
[![Documentation](https://docs.rs/futures-lite/badge.svg)](
https://docs.rs/futures-lite)
A lightweight async prelude.
This crate is a subset of [futures] that compiles an order of magnitude faster, fixes minor
warts in its API, fills in some obvious gaps, and removes almost all unsafe code from it.
In short, this crate aims to be more enjoyable than [futures] but still fully compatible with
it.
The API for this crate is intentionally constrained. Please consult the
[features list] for APIs that are occluded from this crate.
[futures]: https://docs.rs/futures
[features list]: https://github.com/smol-rs/futures-lite/blob/master/FEATURES.md
## Examples
```rust
use futures_lite::future;
fn main() {
future::block_on(async {
println!("Hello world!");
})
}
```
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
#### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

830
vendor/futures-lite/src/future.rs vendored Normal file
View File

@@ -0,0 +1,830 @@
//! Combinators for the [`Future`] trait.
//!
//! # Examples
//!
//! ```
//! use futures_lite::future;
//!
//! # spin_on::spin_on(async {
//! for step in 0..3 {
//! println!("step {}", step);
//!
//! // Give other tasks a chance to run.
//! future::yield_now().await;
//! }
//! # });
//! ```
#[doc(no_inline)]
pub use core::future::{pending, ready, Future, Pending, Ready};
use core::fmt;
use core::pin::Pin;
use core::task::{Context, Poll};
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
#[cfg(feature = "std")]
use std::{
any::Any,
panic::{catch_unwind, AssertUnwindSafe, UnwindSafe},
thread_local,
};
#[cfg(feature = "race")]
use fastrand::Rng;
use pin_project_lite::pin_project;
/// Blocks the current thread on a future.
///
/// # Examples
///
/// ```
/// use futures_lite::future;
///
/// let val = future::block_on(async {
/// 1 + 2
/// });
///
/// assert_eq!(val, 3);
/// ```
#[cfg(feature = "std")]
pub fn block_on<T>(future: impl Future<Output = T>) -> T {
use core::cell::RefCell;
use core::task::Waker;
use parking::Parker;
// Pin the future on the stack.
crate::pin!(future);
// Creates a parker and an associated waker that unparks it.
fn parker_and_waker() -> (Parker, Waker) {
let parker = Parker::new();
let unparker = parker.unparker();
let waker = Waker::from(unparker);
(parker, waker)
}
thread_local! {
// Cached parker and waker for efficiency.
static CACHE: RefCell<(Parker, Waker)> = RefCell::new(parker_and_waker());
}
CACHE.with(|cache| {
// Try grabbing the cached parker and waker.
let tmp_cached;
let tmp_fresh;
let (parker, waker) = match cache.try_borrow_mut() {
Ok(cache) => {
// Use the cached parker and waker.
tmp_cached = cache;
&*tmp_cached
}
Err(_) => {
// Looks like this is a recursive `block_on()` call.
// Create a fresh parker and waker.
tmp_fresh = parker_and_waker();
&tmp_fresh
}
};
let cx = &mut Context::from_waker(waker);
// Keep polling until the future is ready.
loop {
match future.as_mut().poll(cx) {
Poll::Ready(output) => return output,
Poll::Pending => parker.park(),
}
}
})
}
/// Polls a future just once and returns an [`Option`] with the result.
///
/// # Examples
///
/// ```
/// use futures_lite::future;
///
/// # spin_on::spin_on(async {
/// assert_eq!(future::poll_once(future::pending::<()>()).await, None);
/// assert_eq!(future::poll_once(future::ready(42)).await, Some(42));
/// # })
/// ```
pub fn poll_once<T, F>(f: F) -> PollOnce<F>
where
F: Future<Output = T>,
{
PollOnce { f }
}
pin_project! {
/// Future for the [`poll_once()`] function.
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct PollOnce<F> {
#[pin]
f: F,
}
}
impl<F> fmt::Debug for PollOnce<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PollOnce").finish()
}
}
impl<T, F> Future for PollOnce<F>
where
F: Future<Output = T>,
{
type Output = Option<T>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project().f.poll(cx) {
Poll::Ready(t) => Poll::Ready(Some(t)),
Poll::Pending => Poll::Ready(None),
}
}
}
/// Creates a future from a function returning [`Poll`].
///
/// # Examples
///
/// ```
/// use futures_lite::future;
/// use std::task::{Context, Poll};
///
/// # spin_on::spin_on(async {
/// fn f(_: &mut Context<'_>) -> Poll<i32> {
/// Poll::Ready(7)
/// }
///
/// assert_eq!(future::poll_fn(f).await, 7);
/// # })
/// ```
pub fn poll_fn<T, F>(f: F) -> PollFn<F>
where
F: FnMut(&mut Context<'_>) -> Poll<T>,
{
PollFn { f }
}
pin_project! {
/// Future for the [`poll_fn()`] function.
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct PollFn<F> {
f: F,
}
}
impl<F> fmt::Debug for PollFn<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PollFn").finish()
}
}
impl<T, F> Future for PollFn<F>
where
F: FnMut(&mut Context<'_>) -> Poll<T>,
{
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
let this = self.project();
(this.f)(cx)
}
}
/// Wakes the current task and returns [`Poll::Pending`] once.
///
/// This function is useful when we want to cooperatively give time to the task scheduler. It is
/// generally a good idea to yield inside loops because that way we make sure long-running tasks
/// don't prevent other tasks from running.
///
/// # Examples
///
/// ```
/// use futures_lite::future;
///
/// # spin_on::spin_on(async {
/// future::yield_now().await;
/// # })
/// ```
pub fn yield_now() -> YieldNow {
YieldNow(false)
}
/// Future for the [`yield_now()`] function.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct YieldNow(bool);
impl Future for YieldNow {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.0 {
self.0 = true;
cx.waker().wake_by_ref();
Poll::Pending
} else {
Poll::Ready(())
}
}
}
/// Joins two futures, waiting for both to complete.
///
/// # Examples
///
/// ```
/// use futures_lite::future;
///
/// # spin_on::spin_on(async {
/// let a = async { 1 };
/// let b = async { 2 };
///
/// assert_eq!(future::zip(a, b).await, (1, 2));
/// # })
/// ```
pub fn zip<F1, F2>(future1: F1, future2: F2) -> Zip<F1, F2>
where
F1: Future,
F2: Future,
{
Zip {
future1: Some(future1),
future2: Some(future2),
output1: None,
output2: None,
}
}
pin_project! {
/// Future for the [`zip()`] function.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Zip<F1, F2>
where
F1: Future,
F2: Future,
{
#[pin]
future1: Option<F1>,
output1: Option<F1::Output>,
#[pin]
future2: Option<F2>,
output2: Option<F2::Output>,
}
}
/// Extracts the contents of two options and zips them, handling `(Some(_), None)` cases
fn take_zip_from_parts<T1, T2>(o1: &mut Option<T1>, o2: &mut Option<T2>) -> Poll<(T1, T2)> {
match (o1.take(), o2.take()) {
(Some(t1), Some(t2)) => Poll::Ready((t1, t2)),
(o1x, o2x) => {
*o1 = o1x;
*o2 = o2x;
Poll::Pending
}
}
}
impl<F1, F2> Future for Zip<F1, F2>
where
F1: Future,
F2: Future,
{
type Output = (F1::Output, F2::Output);
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
if let Some(future) = this.future1.as_mut().as_pin_mut() {
if let Poll::Ready(out) = future.poll(cx) {
*this.output1 = Some(out);
this.future1.set(None);
}
}
if let Some(future) = this.future2.as_mut().as_pin_mut() {
if let Poll::Ready(out) = future.poll(cx) {
*this.output2 = Some(out);
this.future2.set(None);
}
}
take_zip_from_parts(this.output1, this.output2)
}
}
/// Joins two fallible futures, waiting for both to complete or one of them to error.
///
/// # Examples
///
/// ```
/// use futures_lite::future;
///
/// # spin_on::spin_on(async {
/// let a = async { Ok::<i32, i32>(1) };
/// let b = async { Err::<i32, i32>(2) };
///
/// assert_eq!(future::try_zip(a, b).await, Err(2));
/// # })
/// ```
pub fn try_zip<T1, T2, E, F1, F2>(future1: F1, future2: F2) -> TryZip<F1, T1, F2, T2>
where
F1: Future<Output = Result<T1, E>>,
F2: Future<Output = Result<T2, E>>,
{
TryZip {
future1: Some(future1),
future2: Some(future2),
output1: None,
output2: None,
}
}
pin_project! {
/// Future for the [`try_zip()`] function.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct TryZip<F1, T1, F2, T2> {
#[pin]
future1: Option<F1>,
output1: Option<T1>,
#[pin]
future2: Option<F2>,
output2: Option<T2>,
}
}
impl<T1, T2, E, F1, F2> Future for TryZip<F1, T1, F2, T2>
where
F1: Future<Output = Result<T1, E>>,
F2: Future<Output = Result<T2, E>>,
{
type Output = Result<(T1, T2), E>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
if let Some(future) = this.future1.as_mut().as_pin_mut() {
if let Poll::Ready(out) = future.poll(cx) {
match out {
Ok(t) => {
*this.output1 = Some(t);
this.future1.set(None);
}
Err(err) => return Poll::Ready(Err(err)),
}
}
}
if let Some(future) = this.future2.as_mut().as_pin_mut() {
if let Poll::Ready(out) = future.poll(cx) {
match out {
Ok(t) => {
*this.output2 = Some(t);
this.future2.set(None);
}
Err(err) => return Poll::Ready(Err(err)),
}
}
}
take_zip_from_parts(this.output1, this.output2).map(Ok)
}
}
/// Returns the result of the future that completes first, preferring `future1` if both are ready.
///
/// If you need to treat the two futures fairly without a preference for either, use the [`race()`]
/// function or the [`FutureExt::race()`] method.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, pending, ready};
///
/// # spin_on::spin_on(async {
/// assert_eq!(future::or(ready(1), pending()).await, 1);
/// assert_eq!(future::or(pending(), ready(2)).await, 2);
///
/// // The first future wins.
/// assert_eq!(future::or(ready(1), ready(2)).await, 1);
/// # })
/// ```
pub fn or<T, F1, F2>(future1: F1, future2: F2) -> Or<F1, F2>
where
F1: Future<Output = T>,
F2: Future<Output = T>,
{
Or { future1, future2 }
}
pin_project! {
/// Future for the [`or()`] function and the [`FutureExt::or()`] method.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Or<F1, F2> {
#[pin]
future1: F1,
#[pin]
future2: F2,
}
}
impl<T, F1, F2> Future for Or<F1, F2>
where
F1: Future<Output = T>,
F2: Future<Output = T>,
{
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
if let Poll::Ready(t) = this.future1.poll(cx) {
return Poll::Ready(t);
}
if let Poll::Ready(t) = this.future2.poll(cx) {
return Poll::Ready(t);
}
Poll::Pending
}
}
/// Fuse a future such that `poll` will never again be called once it has
/// completed. This method can be used to turn any `Future` into a
/// `FusedFuture`.
///
/// Normally, once a future has returned `Poll::Ready` from `poll`,
/// any further calls could exhibit bad behavior such as blocking
/// forever, panicking, never returning, etc. If it is known that `poll`
/// may be called too often then this method can be used to ensure that it
/// has defined semantics.
///
/// If a `fuse`d future is `poll`ed after having returned `Poll::Ready`
/// previously, it will return `Poll::Pending`, from `poll` again (and will
/// continue to do so for all future calls to `poll`).
///
/// This combinator will drop the underlying future as soon as it has been
/// completed to ensure resources are reclaimed as soon as possible.
pub fn fuse<F>(future: F) -> Fuse<F>
where
F: Future + Sized,
{
Fuse::new(future)
}
pin_project! {
/// [`Future`] for the [`fuse`] method.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Fuse<Fut> {
#[pin]
inner: Option<Fut>,
}
}
impl<Fut> Fuse<Fut> {
fn new(f: Fut) -> Self {
Self { inner: Some(f) }
}
}
impl<Fut: Future> Future for Fuse<Fut> {
type Output = Fut::Output;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Fut::Output> {
match self
.as_mut()
.project()
.inner
.as_pin_mut()
.map(|f| f.poll(cx))
{
Some(Poll::Ready(output)) => {
self.project().inner.set(None);
Poll::Ready(output)
}
Some(Poll::Pending) | None => Poll::Pending,
}
}
}
/// Returns the result of the future that completes first, with no preference if both are ready.
///
/// Each time [`Race`] is polled, the two inner futures are polled in random order. Therefore, no
/// future takes precedence over the other if both can complete at the same time.
///
/// If you have preference for one of the futures, use the [`or()`] function or the
/// [`FutureExt::or()`] method.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, pending, ready};
///
/// # spin_on::spin_on(async {
/// assert_eq!(future::race(ready(1), pending()).await, 1);
/// assert_eq!(future::race(pending(), ready(2)).await, 2);
///
/// // One of the two futures is randomly chosen as the winner.
/// let res = future::race(ready(1), ready(2)).await;
/// # })
/// ```
#[cfg(all(feature = "race", feature = "std"))]
pub fn race<T, F1, F2>(future1: F1, future2: F2) -> Race<F1, F2>
where
F1: Future<Output = T>,
F2: Future<Output = T>,
{
Race {
future1,
future2,
rng: Rng::new(),
}
}
/// Race two futures but with a predefined random seed.
///
/// This function is identical to [`race`], but instead of using a random seed from a thread-local
/// RNG, it allows the user to provide a seed. It is useful for when you already have a source of
/// randomness available, or if you want to use a fixed seed.
///
/// See documentation of the [`race`] function for features and caveats.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, pending, ready};
///
/// // A fixed seed is used, so the result is deterministic.
/// const SEED: u64 = 0x42;
///
/// # spin_on::spin_on(async {
/// assert_eq!(future::race_with_seed(ready(1), pending(), SEED).await, 1);
/// assert_eq!(future::race_with_seed(pending(), ready(2), SEED).await, 2);
///
/// // One of the two futures is randomly chosen as the winner.
/// let res = future::race_with_seed(ready(1), ready(2), SEED).await;
/// # })
/// ```
#[cfg(feature = "race")]
pub fn race_with_seed<T, F1, F2>(future1: F1, future2: F2, seed: u64) -> Race<F1, F2>
where
F1: Future<Output = T>,
F2: Future<Output = T>,
{
Race {
future1,
future2,
rng: Rng::with_seed(seed),
}
}
#[cfg(feature = "race")]
pin_project! {
/// Future for the [`race()`] function and the [`FutureExt::race()`] method.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Race<F1, F2> {
#[pin]
future1: F1,
#[pin]
future2: F2,
rng: Rng,
}
}
#[cfg(feature = "race")]
impl<T, F1, F2> Future for Race<F1, F2>
where
F1: Future<Output = T>,
F2: Future<Output = T>,
{
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
if this.rng.bool() {
if let Poll::Ready(t) = this.future1.poll(cx) {
return Poll::Ready(t);
}
if let Poll::Ready(t) = this.future2.poll(cx) {
return Poll::Ready(t);
}
} else {
if let Poll::Ready(t) = this.future2.poll(cx) {
return Poll::Ready(t);
}
if let Poll::Ready(t) = this.future1.poll(cx) {
return Poll::Ready(t);
}
}
Poll::Pending
}
}
#[cfg(feature = "std")]
pin_project! {
/// Future for the [`FutureExt::catch_unwind()`] method.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CatchUnwind<F> {
#[pin]
inner: F,
}
}
#[cfg(feature = "std")]
impl<F: Future + UnwindSafe> Future for CatchUnwind<F> {
type Output = Result<F::Output, Box<dyn Any + Send>>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
catch_unwind(AssertUnwindSafe(|| this.inner.poll(cx)))?.map(Ok)
}
}
/// Type alias for `Pin<Box<dyn Future<Output = T> + Send + 'static>>`.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, FutureExt};
///
/// // These two lines are equivalent:
/// let f1: future::Boxed<i32> = async { 1 + 2 }.boxed();
/// let f2: future::Boxed<i32> = Box::pin(async { 1 + 2 });
/// ```
#[cfg(feature = "alloc")]
pub type Boxed<T> = Pin<Box<dyn Future<Output = T> + Send + 'static>>;
/// Type alias for `Pin<Box<dyn Future<Output = T> + 'static>>`.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, FutureExt};
///
/// // These two lines are equivalent:
/// let f1: future::BoxedLocal<i32> = async { 1 + 2 }.boxed_local();
/// let f2: future::BoxedLocal<i32> = Box::pin(async { 1 + 2 });
/// ```
#[cfg(feature = "alloc")]
pub type BoxedLocal<T> = Pin<Box<dyn Future<Output = T> + 'static>>;
/// Extension trait for [`Future`].
pub trait FutureExt: Future {
/// A convenience for calling [`Future::poll()`] on `!`[`Unpin`] types.
fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>
where
Self: Unpin,
{
Future::poll(Pin::new(self), cx)
}
/// Returns the result of `self` or `other` future, preferring `self` if both are ready.
///
/// If you need to treat the two futures fairly without a preference for either, use the
/// [`race()`] function or the [`FutureExt::race()`] method.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{pending, ready, FutureExt};
///
/// # spin_on::spin_on(async {
/// assert_eq!(ready(1).or(pending()).await, 1);
/// assert_eq!(pending().or(ready(2)).await, 2);
///
/// // The first future wins.
/// assert_eq!(ready(1).or(ready(2)).await, 1);
/// # })
/// ```
fn or<F>(self, other: F) -> Or<Self, F>
where
Self: Sized,
F: Future<Output = Self::Output>,
{
Or {
future1: self,
future2: other,
}
}
/// Returns the result of `self` or `other` future, with no preference if both are ready.
///
/// Each time [`Race`] is polled, the two inner futures are polled in random order. Therefore,
/// no future takes precedence over the other if both can complete at the same time.
///
/// If you have preference for one of the futures, use the [`or()`] function or the
/// [`FutureExt::or()`] method.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{pending, ready, FutureExt};
///
/// # spin_on::spin_on(async {
/// assert_eq!(ready(1).race(pending()).await, 1);
/// assert_eq!(pending().race(ready(2)).await, 2);
///
/// // One of the two futures is randomly chosen as the winner.
/// let res = ready(1).race(ready(2)).await;
/// # })
/// ```
#[cfg(all(feature = "std", feature = "race"))]
fn race<F>(self, other: F) -> Race<Self, F>
where
Self: Sized,
F: Future<Output = Self::Output>,
{
Race {
future1: self,
future2: other,
rng: Rng::new(),
}
}
/// Catches panics while polling the future.
///
/// # Examples
///
/// ```
/// use futures_lite::future::FutureExt;
///
/// # spin_on::spin_on(async {
/// let fut1 = async {}.catch_unwind();
/// let fut2 = async { panic!() }.catch_unwind();
///
/// assert!(fut1.await.is_ok());
/// assert!(fut2.await.is_err());
/// # })
/// ```
#[cfg(feature = "std")]
fn catch_unwind(self) -> CatchUnwind<Self>
where
Self: Sized + UnwindSafe,
{
CatchUnwind { inner: self }
}
/// Boxes the future and changes its type to `dyn Future + Send + 'a`.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, FutureExt};
///
/// # spin_on::spin_on(async {
/// let a = future::ready('a');
/// let b = future::pending();
///
/// // Futures of different types can be stored in
/// // the same collection when they are boxed:
/// let futures = vec![a.boxed(), b.boxed()];
/// # })
/// ```
#[cfg(feature = "alloc")]
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
where
Self: Sized + Send + 'a,
{
Box::pin(self)
}
/// Boxes the future and changes its type to `dyn Future + 'a`.
///
/// # Examples
///
/// ```
/// use futures_lite::future::{self, FutureExt};
///
/// # spin_on::spin_on(async {
/// let a = future::ready('a');
/// let b = future::pending();
///
/// // Futures of different types can be stored in
/// // the same collection when they are boxed:
/// let futures = vec![a.boxed_local(), b.boxed_local()];
/// # })
/// ```
#[cfg(feature = "alloc")]
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>
where
Self: Sized + 'a,
{
Box::pin(self)
}
}
impl<F: Future + ?Sized> FutureExt for F {}

3102
vendor/futures-lite/src/io.rs vendored Normal file

File diff suppressed because it is too large Load Diff

147
vendor/futures-lite/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,147 @@
//! Futures, streams, and async I/O combinators.
//!
//! This crate is a subset of [futures] that compiles an order of magnitude faster, fixes minor
//! warts in its API, fills in some obvious gaps, and removes almost all unsafe code from it.
//!
//! In short, this crate aims to be more enjoyable than [futures] but still fully compatible with
//! it.
//!
//! The API for this crate is intentionally constrained. Please consult the [features list] for
//! APIs that are occluded from this crate.
//!
//! [futures]: https://docs.rs/futures
//! [features list]: https://github.com/smol-rs/futures-lite/blob/master/FEATURES.md
//!
//! # Examples
//!
#![cfg_attr(feature = "std", doc = "```no_run")]
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
//! use futures_lite::future;
//!
//! fn main() {
//! future::block_on(async {
//! println!("Hello world!");
//! })
//! }
//! ```
#![no_std]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![allow(clippy::needless_borrow)] // suggest code that doesn't work on MSRV
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
#[doc(no_inline)]
pub use crate::io::{
AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt, AsyncWrite,
AsyncWriteExt,
};
#[doc(no_inline)]
pub use crate::{
future::{Future, FutureExt},
stream::{Stream, StreamExt},
};
pub mod future;
pub mod prelude;
pub mod stream;
#[cfg(feature = "std")]
pub mod io;
/// Unwraps `Poll<T>` or returns [`Pending`][`core::task::Poll::Pending`].
///
/// # Examples
///
/// ```
/// use futures_lite::{future, prelude::*, ready};
/// use std::pin::Pin;
/// use std::task::{Context, Poll};
///
/// fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
/// let mut fut = future::ready(42);
/// let fut = Pin::new(&mut fut);
///
/// let num = ready!(fut.poll(cx));
/// # drop(num);
/// // ... use num
///
/// Poll::Ready(())
/// }
/// ```
///
/// The `ready!` call expands to:
///
/// ```
/// # use futures_lite::{future, prelude::*, ready};
/// # use std::pin::Pin;
/// # use std::task::{Context, Poll};
/// #
/// # fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
/// # let mut fut = future::ready(42);
/// # let fut = Pin::new(&mut fut);
/// #
/// let num = match fut.poll(cx) {
/// Poll::Ready(t) => t,
/// Poll::Pending => return Poll::Pending,
/// };
/// # drop(num);
/// # // ... use num
/// #
/// # Poll::Ready(())
/// # }
/// ```
#[macro_export]
macro_rules! ready {
($e:expr $(,)?) => {
match $e {
core::task::Poll::Ready(t) => t,
core::task::Poll::Pending => return core::task::Poll::Pending,
}
};
}
/// Pins a variable of type `T` on the stack and rebinds it as `Pin<&mut T>`.
///
/// ```
/// use futures_lite::{future, pin};
/// use std::fmt::Debug;
/// use std::future::Future;
/// use std::pin::Pin;
/// use std::time::Instant;
///
/// // Inspects each invocation of `Future::poll()`.
/// async fn inspect<T: Debug>(f: impl Future<Output = T>) -> T {
/// pin!(f);
/// future::poll_fn(|cx| dbg!(f.as_mut().poll(cx))).await
/// }
///
/// # spin_on::spin_on(async {
/// let f = async { 1 + 2 };
/// inspect(f).await;
/// # })
/// ```
#[macro_export]
macro_rules! pin {
($($x:ident),* $(,)?) => {
$(
let mut $x = $x;
#[allow(unused_mut)]
let mut $x = unsafe {
core::pin::Pin::new_unchecked(&mut $x)
};
)*
}
}

23
vendor/futures-lite/src/prelude.rs vendored Normal file
View File

@@ -0,0 +1,23 @@
//! Traits [`Future`], [`Stream`], [`AsyncRead`], [`AsyncWrite`], [`AsyncBufRead`],
//! [`AsyncSeek`], and their extensions.
//!
//! # Examples
//!
//! ```
//! use futures_lite::prelude::*;
//! ```
#[doc(no_inline)]
pub use crate::{
future::{Future, FutureExt as _},
stream::{Stream, StreamExt as _},
};
#[cfg(feature = "std")]
#[doc(no_inline)]
pub use crate::{
io::{AsyncBufRead, AsyncBufReadExt as _},
io::{AsyncRead, AsyncReadExt as _},
io::{AsyncSeek, AsyncSeekExt as _},
io::{AsyncWrite, AsyncWriteExt as _},
};

3542
vendor/futures-lite/src/stream.rs vendored Normal file

File diff suppressed because it is too large Load Diff