diff options
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 13 | ||||
-rw-r--r-- | CHANGELOG.md | 14 | ||||
-rw-r--r-- | Cargo.lock | 366 | ||||
-rw-r--r-- | Cargo.toml | 10 | ||||
-rw-r--r-- | Cargo.toml.orig | 14 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 27 | ||||
-rw-r--r-- | TEST_MAPPING | 11 | ||||
-rw-r--r-- | cargo2android.json | 4 | ||||
-rw-r--r-- | examples/tcp_accept.rs | 2 | ||||
-rw-r--r-- | src/async_stream.rs | 8 | ||||
-rw-r--r-- | src/lib.rs | 88 | ||||
-rw-r--r-- | src/yielder.rs | 6 | ||||
-rw-r--r-- | tests/stream.rs | 73 | ||||
-rw-r--r-- | tests/ui/yield_bad_expr_in_macro.rs | 11 | ||||
-rw-r--r-- | tests/ui/yield_bad_expr_in_macro.stderr | 5 | ||||
-rw-r--r-- | tests/ui/yield_in_async.stderr | 7 | ||||
-rw-r--r-- | tests/ui/yield_in_closure.stderr | 6 |
19 files changed, 394 insertions, 281 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 29bac5d..620b2af 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "d346ad2d77b11855969b82c9d16bd78ec84e4863" + "sha1": "b28da881695e3c66e1782f0c2c330d4e162eb7c2" } } @@ -1,4 +1,5 @@ -// This file is generated by cargo2android.py --run --dependencies --device. +// This file is generated by cargo2android.py --config cargo2android.json. +// Do not modify this file as changes will be overridden on upgrade. package { default_applicable_licenses: ["external_rust_crates_async-stream_license"], @@ -21,6 +22,8 @@ rust_library { name: "libasync_stream", host_supported: true, crate_name: "async_stream", + cargo_env_compat: true, + cargo_pkg_version: "0.3.2", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -28,11 +31,3 @@ rust_library { ], proc_macros: ["libasync_stream_impl"], } - -// dependent_library ["feature_list"] -// async-stream-impl-0.3.0 -// futures-core-0.3.12 "alloc,default,std" -// proc-macro2-1.0.24 "default,proc-macro" -// quote-1.0.8 "default,proc-macro" -// syn-1.0.60 "clone-impls,default,derive,extra-traits,full,parsing,printing,proc-macro,quote,visit-mut" -// unicode-xid-0.2.1 "default" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..bd7f60f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# 0.3.2 + +* Expand `yield` in internal macro calls (#57) + +# 0.3.1 + +* Support reexporting (#46) +* Allow yielding `!Unpin` values (#50) +* Implement `Stream::size_hint` method on `AsyncStream` (#40) +* Documentation improvements + +# 0.3.0 + +* Remove proc-macro-hack (#30) @@ -1,14 +1,20 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] -name = "arc-swap" -version = "0.4.7" +name = "async-stream" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" +checksum = "3670df70cbc01729f901f94c887814b3c68db038aad1329a418bae178bc5295c" +dependencies = [ + "async-stream-impl", + "futures-core", +] [[package]] name = "async-stream" -version = "0.3.0" +version = "0.3.2" dependencies = [ "async-stream-impl", "futures-core", @@ -20,9 +26,9 @@ dependencies = [ [[package]] name = "async-stream-impl" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" dependencies = [ "proc-macro2", "quote", @@ -30,6 +36,12 @@ dependencies = [ ] [[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -37,50 +49,29 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bytes" -version = "0.5.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "futures-core" -version = "0.3.5" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" +checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" [[package]] name = "futures-macro" -version = "0.3.5" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" +checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" dependencies = [ + "autocfg", "proc-macro-hack", "proc-macro2", "quote", @@ -89,23 +80,21 @@ dependencies = [ [[package]] name = "futures-task" -version = "0.3.5" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" -dependencies = [ - "once_cell", -] +checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" [[package]] name = "futures-util" -version = "0.3.5" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" +checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" dependencies = [ + "autocfg", "futures-core", "futures-macro", "futures-task", - "pin-project", + "pin-project-lite", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -120,37 +109,27 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "hermit-abi" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] [[package]] -name = "iovec" -version = "0.1.4" +name = "instant" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "libc", + "cfg-if", ] [[package]] name = "itoa" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "lazy_static" @@ -160,98 +139,63 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.74" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] -name = "log" -version = "0.4.11" +name = "lock_api" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" dependencies = [ - "cfg-if", + "scopeguard", ] [[package]] -name = "memchr" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" - -[[package]] -name = "mio" -version = "0.6.22" +name = "log" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ "cfg-if", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.1", - "net2", - "slab", - "winapi 0.2.8", ] [[package]] -name = "mio-named-pipes" -version = "0.1.7" +name = "memchr" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" -dependencies = [ - "log", - "mio", - "miow 0.3.5", - "winapi 0.3.9", -] +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] -name = "mio-uds" -version = "0.6.8" +name = "mio" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" +checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" dependencies = [ - "iovec", "libc", - "mio", -] - -[[package]] -name = "miow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "log", + "miow", + "ntapi", + "winapi", ] [[package]] name = "miow" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "socket2", - "winapi 0.3.9", + "winapi", ] [[package]] -name = "net2" -version = "0.2.34" +name = "ntapi" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "cfg-if", - "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -266,35 +210,40 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] -name = "pin-project" -version = "0.4.23" +name = "parking_lot" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" dependencies = [ - "pin-project-internal", + "instant", + "lock_api", + "parking_lot_core", ] [[package]] -name = "pin-project-internal" -version = "0.4.23" +name = "parking_lot_core" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "proc-macro2", - "quote", - "syn", + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", ] [[package]] name = "pin-project-lite" -version = "0.1.7" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -304,39 +253,42 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro-hack" -version = "0.5.18" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro-nested" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.19" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +dependencies = [ + "bitflags", +] [[package]] name = "ryu" @@ -345,19 +297,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] name = "serde" -version = "1.0.114" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ "proc-macro2", "quote", @@ -366,9 +324,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.57" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -377,37 +335,30 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" dependencies = [ - "arc-swap", "libc", ] [[package]] name = "slab" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" [[package]] -name = "socket2" -version = "0.3.12" +name = "smallvec" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "winapi 0.3.9", -] +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "syn" -version = "1.0.38" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -416,42 +367,38 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] [[package]] name = "tokio" -version = "0.2.22" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" dependencies = [ + "autocfg", "bytes", - "fnv", - "futures-core", - "iovec", - "lazy_static", "libc", "memchr", "mio", - "mio-named-pipes", - "mio-uds", "num_cpus", + "once_cell", + "parking_lot", "pin-project-lite", "signal-hook-registry", - "slab", "tokio-macros", - "winapi 0.3.9", + "winapi", ] [[package]] name = "tokio-macros" -version = "0.2.5" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" dependencies = [ "proc-macro2", "quote", @@ -459,30 +406,43 @@ dependencies = [ ] [[package]] +name = "tokio-stream" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8864d706fdb3cc0843a49647ac892720dac98a6eeb818b77190592cf4994066" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] name = "tokio-test" -version = "0.2.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed0049c119b6d505c4447f5c64873636c7af6c75ab0d45fd9f618d82acb8016d" +checksum = "53474327ae5e166530d17f2d956afcb4f8a004de581b3cae10f12006bc8163e3" dependencies = [ + "async-stream 0.3.0", "bytes", "futures-core", "tokio", + "tokio-stream", ] [[package]] name = "toml" -version = "0.5.6" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ "serde", ] [[package]] name = "trybuild" -version = "1.0.31" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a4d94e6adf00b96b1ab94fcfcd8c3cf916733b39adf90c8f72693629887b9b8" +checksum = "1768998d9a3b179411618e377dbb134c58a88cda284b0aa71c42c40660127d46" dependencies = [ "glob", "lazy_static", @@ -494,15 +454,9 @@ dependencies = [ [[package]] name = "unicode-xid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - -[[package]] -name = "winapi" -version = "0.2.8" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "winapi" @@ -515,12 +469,6 @@ dependencies = [ ] [[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -532,7 +480,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -540,13 +488,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] @@ -13,16 +13,16 @@ [package] edition = "2018" name = "async-stream" -version = "0.3.0" +version = "0.3.2" authors = ["Carl Lerche <me@carllerche.com>"] description = "Asynchronous streams using async & await notation" homepage = "https://github.com/tokio-rs/async-stream" -documentation = "https://docs.rs/async-stream/0.3.0/async-stream" +documentation = "https://docs.rs/async-stream" readme = "README.md" license = "MIT" repository = "https://github.com/tokio-rs/async-stream" [dependencies.async-stream-impl] -version = "0.3.0" +version = "=0.3.2" [dependencies.futures-core] version = "0.3" @@ -30,11 +30,11 @@ version = "0.3" version = "0.3" [dev-dependencies.tokio] -version = "0.2" +version = "1" features = ["full"] [dev-dependencies.tokio-test] -version = "0.2" +version = "0.4" [dev-dependencies.trybuild] version = "1" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index aca3396..06ccf45 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -2,29 +2,25 @@ name = "async-stream" # When releasing to crates.io: # - Update version number -# - lib.rs: html_root_url. # - README.md # - Update CHANGELOG.md -# - Update doc URL. -# - Cargo.toml -# - README.md # - Create git tag -version = "0.3.0" +version = "0.3.2" edition = "2018" license = "MIT" authors = ["Carl Lerche <me@carllerche.com>"] description = "Asynchronous streams using async & await notation" -documentation = "https://docs.rs/async-stream/0.3.0/async-stream" +documentation = "https://docs.rs/async-stream" homepage = "https://github.com/tokio-rs/async-stream" repository = "https://github.com/tokio-rs/async-stream" readme = "README.md" [dependencies] -async-stream-impl = { version = "0.3.0", path = "../async-stream-impl" } +async-stream-impl = { version = "=0.3.2", path = "../async-stream-impl" } futures-core = "0.3" [dev-dependencies] futures-util = "0.3" -tokio = { version = "0.2", features = ["full"] } -tokio-test = "0.2" +tokio = { version = "1", features = ["full"] } +tokio-test = "0.4" trybuild = "1" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/async-stream/async-stream-0.3.0.crate" + value: "https://static.crates.io/crates/async-stream/async-stream-0.3.2.crate" } - version: "0.3.0" + version: "0.3.2" license_type: NOTICE last_upgrade_date { year: 2021 - month: 2 - day: 8 + month: 6 + day: 21 } } @@ -4,7 +4,7 @@ Asynchronous stream of elements. Provides two macros, `stream!` and `try_stream!`, allowing the caller to define asynchronous streams of elements. These are implemented using `async` -& `await` notation. The `stream!` macro works without unstable features. +& `await` notation. This crate works without unstable features. The `stream!` macro returns an anonymous type implementing the [`Stream`] trait. The `Item` associated type is the type of the values yielded from the @@ -68,7 +68,8 @@ async fn main() { } ``` -Streams may be implemented in terms of other streams: +Streams may be implemented in terms of other streams - `async-stream` provides `for await` +syntax to assist with this: ```rust use async_stream::stream; @@ -89,8 +90,7 @@ fn double<S: Stream<Item = u32>>(input: S) -> impl Stream<Item = u32> { stream! { - pin_mut!(input); - while let Some(value) = input.next().await { + for await value in input { yield value * 2; } } @@ -124,7 +124,7 @@ fn bind_and_accept(addr: SocketAddr) -> impl Stream<Item = io::Result<TcpStream>> { try_stream! { - let mut listener = TcpListener::bind(&addr)?; + let mut listener = TcpListener::bind(addr).await?; loop { let (stream, addr) = listener.accept().await?; @@ -138,9 +138,7 @@ fn bind_and_accept(addr: SocketAddr) ## Implementation The `stream!` and `try_stream!` macros are implemented using proc macros. -Given that proc macros in expression position are not supported on stable -rust, a hack similar to the one provided by the [`proc-macro-hack`] crate is -used. The macro searches the syntax tree for instances of `sender.send($expr)` and +The macro searches the syntax tree for instances of `sender.send($expr)` and transforms them into `sender.send($expr).await`. The stream uses a lightweight sender to send values from the stream @@ -150,17 +148,10 @@ stored on the stack. A pointer to the cell is stored in a thread local and `sender.send(value)` stores the value that cell and yields back to the caller. -## Limitations - -`async-stream` suffers from the same limitations as the [`proc-macro-hack`] -crate. Primarily, nesting support must be implemented using a `TT-muncher`. -If large `stream!` blocks are used, the caller will be required to add -`#![recursion_limit = "..."]` to their crate. - -A `stream!` macro may only contain up to 64 macro invocations. - [`Stream`]: https://docs.rs/futures-core/*/futures_core/stream/trait.Stream.html -[`proc-macro-hack`]: https://github.com/dtolnay/proc-macro-hack/ + +## Supported Rust Versions +`async-stream` is built against the latest stable release. The minimum supported version is 1.45 due to [function-like procedural macros in expression, pattern, and statement positions](https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements). ## License diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 0000000..dfc3524 --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,11 @@ +// Generated by update_crate_tests.py for tests that depend on this crate. +{ + "imports": [ + { + "path": "external/rust/crates/tokio" + }, + { + "path": "external/rust/crates/tokio-test" + } + ] +} diff --git a/cargo2android.json b/cargo2android.json new file mode 100644 index 0000000..bf78496 --- /dev/null +++ b/cargo2android.json @@ -0,0 +1,4 @@ +{ + "device": true, + "run": true +}
\ No newline at end of file diff --git a/examples/tcp_accept.rs b/examples/tcp_accept.rs index 023e1a1..1b69bda 100644 --- a/examples/tcp_accept.rs +++ b/examples/tcp_accept.rs @@ -5,7 +5,7 @@ use tokio::net::TcpListener; #[tokio::main] async fn main() { - let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let incoming = stream! { loop { diff --git a/src/async_stream.rs b/src/async_stream.rs index 30115df..f60c87e 100644 --- a/src/async_stream.rs +++ b/src/async_stream.rs @@ -66,4 +66,12 @@ where } } } + + fn size_hint(&self) -> (usize, Option<usize>) { + if self.done { + (0, Some(0)) + } else { + (0, None) + } + } } @@ -1,4 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/async-stream/0.3.0")] #![warn( missing_debug_implementations, missing_docs, @@ -11,7 +10,7 @@ //! //! Provides two macros, `stream!` and `try_stream!`, allowing the caller to //! define asynchronous streams of elements. These are implemented using `async` -//! & `await` notation. The `stream!` macro works without unstable features. +//! & `await` notation. This crate works without unstable features. //! //! The `stream!` macro returns an anonymous type implementing the [`Stream`] //! trait. The `Item` associated type is the type of the values yielded from the @@ -75,7 +74,8 @@ //! } //! ``` //! -//! Streams may be implemented in terms of other streams: +//! Streams may be implemented in terms of other streams - `async-stream` provides `for await` +//! syntax to assist with this: //! //! ```rust //! use async_stream::stream; @@ -96,8 +96,7 @@ //! -> impl Stream<Item = u32> //! { //! stream! { -//! pin_mut!(input); -//! while let Some(value) = input.next().await { +//! for await value in input { //! yield value * 2; //! } //! } @@ -145,9 +144,7 @@ //! # Implementation //! //! The `stream!` and `try_stream!` macros are implemented using proc macros. -//! Given that proc macros in expression position are not supported on stable -//! rust, a hack similar to the one provided by the [`proc-macro-hack`] crate is -//! used. The macro searches the syntax tree for instances of `sender.send($expr)` and +//! The macro searches the syntax tree for instances of `sender.send($expr)` and //! transforms them into `sender.send($expr).await`. //! //! The stream uses a lightweight sender to send values from the stream @@ -164,11 +161,82 @@ mod next; #[doc(hidden)] pub mod yielder; -// Used by the macro, but not intended to be accessed publically. +// Used by the macro, but not intended to be accessed publicly. #[doc(hidden)] pub use crate::async_stream::AsyncStream; -pub use async_stream_impl::{stream, try_stream}; +#[doc(hidden)] +pub use async_stream_impl; + +/// Asynchronous stream +/// +/// See [crate](index.html) documentation for more details. +/// +/// # Examples +/// +/// ``` +/// use async_stream::stream; +/// +/// use futures_util::pin_mut; +/// use futures_util::stream::StreamExt; +/// +/// #[tokio::main] +/// async fn main() { +/// let s = stream! { +/// for i in 0..3 { +/// yield i; +/// } +/// }; +/// +/// pin_mut!(s); // needed for iteration +/// +/// while let Some(value) = s.next().await { +/// println!("got {}", value); +/// } +/// } +/// ``` +#[macro_export] +macro_rules! stream { + ($($tt:tt)*) => { + $crate::async_stream_impl::stream_inner!(($crate) $($tt)*) + } +} + +/// Asynchronous fallible stream +/// +/// See [crate](index.html) documentation for more details. +/// +/// # Examples +/// +/// ``` +/// use tokio::net::{TcpListener, TcpStream}; +/// +/// use async_stream::try_stream; +/// use futures_core::stream::Stream; +/// +/// use std::io; +/// use std::net::SocketAddr; +/// +/// fn bind_and_accept(addr: SocketAddr) +/// -> impl Stream<Item = io::Result<TcpStream>> +/// { +/// try_stream! { +/// let mut listener = TcpListener::bind(addr).await?; +/// +/// loop { +/// let (stream, addr) = listener.accept().await?; +/// println!("received on {:?}", addr); +/// yield stream; +/// } +/// } +/// } +/// ``` +#[macro_export] +macro_rules! try_stream { + ($($tt:tt)*) => { + $crate::async_stream_impl::try_stream_inner!(($crate) $($tt)*) + } +} #[doc(hidden)] pub mod reexport { diff --git a/src/yielder.rs b/src/yielder.rs index 49c4133..1ee523f 100644 --- a/src/yielder.rs +++ b/src/yielder.rs @@ -33,7 +33,7 @@ thread_local!(static STORE: Cell<*mut ()> = Cell::new(ptr::null_mut())); // ===== impl Sender ===== -impl<T: Unpin> Sender<T> { +impl<T> Sender<T> { pub fn send(&mut self, value: T) -> impl Future<Output = ()> { Send { value: Some(value) } } @@ -43,7 +43,9 @@ struct Send<T> { value: Option<T>, } -impl<T: Unpin> Future for Send<T> { +impl<T> Unpin for Send<T> {} + +impl<T> Future for Send<T> { type Output = (); fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> { diff --git a/tests/stream.rs b/tests/stream.rs index e46fc5a..77b3813 100644 --- a/tests/stream.rs +++ b/tests/stream.rs @@ -81,6 +81,42 @@ async fn yield_multi_value() { } #[tokio::test] +async fn unit_yield_in_select() { + use tokio::select; + + async fn do_stuff_async() {} + + let s = stream! { + select! { + _ = do_stuff_async() => yield, + else => yield, + } + }; + + let values: Vec<_> = s.collect().await; + assert_eq!(values.len(), 1); +} + +#[tokio::test] +async fn yield_with_select() { + use tokio::select; + + async fn do_stuff_async() {} + async fn more_async_work() {} + + let s = stream! { + select! { + _ = do_stuff_async() => yield "hey", + _ = more_async_work() => yield "hey", + else => yield "hey", + } + }; + + let values: Vec<_> = s.collect().await; + assert_eq!(values, vec!["hey"]); +} + +#[tokio::test] async fn return_stream() { fn build_stream() -> impl Stream<Item = u32> { stream! { @@ -101,7 +137,7 @@ async fn return_stream() { #[tokio::test] async fn consume_channel() { - let (mut tx, mut rx) = mpsc::channel(10); + let (tx, mut rx) = mpsc::channel(10); let s = stream! { while let Some(v) = rx.recv().await { @@ -158,6 +194,41 @@ async fn stream_in_stream() { assert_eq!(3, values.len()); } +#[tokio::test] +async fn yield_non_unpin_value() { + let s: Vec<_> = stream! { + for i in 0..3 { + yield async move { i }; + } + } + .buffered(1) + .collect() + .await; + + assert_eq!(s, vec![0, 1, 2]); +} + +#[test] +fn inner_try_stream() { + use async_stream::try_stream; + use tokio::select; + + async fn do_stuff_async() {} + + let _ = stream! { + select! { + _ = do_stuff_async() => { + let another_s = try_stream! { + yield; + }; + let _: Result<(), ()> = Box::pin(another_s).next().await.unwrap(); + }, + else => {}, + } + yield + }; +} + #[test] fn test() { let t = trybuild::TestCases::new(); diff --git a/tests/ui/yield_bad_expr_in_macro.rs b/tests/ui/yield_bad_expr_in_macro.rs new file mode 100644 index 0000000..37fcd34 --- /dev/null +++ b/tests/ui/yield_bad_expr_in_macro.rs @@ -0,0 +1,11 @@ +use async_stream::stream; + +fn main() { + async fn work() {} + + stream! { + tokio::select! { + _ = work() => yield fn f() {}, + } + }; +} diff --git a/tests/ui/yield_bad_expr_in_macro.stderr b/tests/ui/yield_bad_expr_in_macro.stderr new file mode 100644 index 0000000..71d9075 --- /dev/null +++ b/tests/ui/yield_bad_expr_in_macro.stderr @@ -0,0 +1,5 @@ +error: expected expression + --> $DIR/yield_bad_expr_in_macro.rs:8:33 + | +8 | _ = work() => yield fn f() {}, + | ^^ diff --git a/tests/ui/yield_in_async.stderr b/tests/ui/yield_in_async.stderr index 1e9d8ff..19691eb 100644 --- a/tests/ui/yield_in_async.stderr +++ b/tests/ui/yield_in_async.stderr @@ -12,7 +12,7 @@ error[E0727]: `async` generators are not yet supported 6 | yield 123; | ^^^^^^^^^ -error[E0271]: type mismatch resolving `<[static generator@$DIR/tests/ui/yield_in_async.rs:4:5: 10:7 _] as std::ops::Generator<std::future::ResumeTy>>::Yield == ()` +error[E0271]: type mismatch resolving `<[static generator@$DIR/src/lib.rs:201:9: 201:67] as Generator<ResumeTy>>::Yield == ()` --> $DIR/yield_in_async.rs:4:5 | 4 | / stream! { @@ -23,6 +23,8 @@ error[E0271]: type mismatch resolving `<[static generator@$DIR/tests/ui/yield_in 9 | | let v = f.await; 10 | | }; | |______^ expected `()`, found integer + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0698]: type inside `async` block must be known in this context --> $DIR/yield_in_async.rs:6:19 @@ -71,6 +73,3 @@ note: the type is part of the `async` block because of this `await` | 9 | let v = f.await; | ^^^^^^^ - -Some errors have detailed explanations: E0271, E0658, E0698, E0727. -For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/yield_in_closure.stderr b/tests/ui/yield_in_closure.stderr index 77092e0..2506e18 100644 --- a/tests/ui/yield_in_closure.stderr +++ b/tests/ui/yield_in_closure.stderr @@ -6,13 +6,13 @@ error[E0658]: yield syntax is experimental | = note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information -error[E0277]: expected a `std::ops::FnOnce<(&str,)>` closure, found `[generator@$DIR/tests/ui/yield_in_closure.rs:4:5: 10:7 _]` +error[E0277]: expected a `FnOnce<(&str,)>` closure, found `[generator@$DIR/src/lib.rs:201:9: 201:67]` --> $DIR/yield_in_closure.rs:6:14 | 6 | .and_then(|v| { - | ^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `[generator@$DIR/tests/ui/yield_in_closure.rs:4:5: 10:7 _]` + | ^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `[generator@$DIR/src/lib.rs:201:9: 201:67]` | - = help: the trait `std::ops::FnOnce<(&str,)>` is not implemented for `[generator@$DIR/tests/ui/yield_in_closure.rs:4:5: 10:7 _]` + = help: the trait `FnOnce<(&str,)>` is not implemented for `[generator@$DIR/src/lib.rs:201:9: 201:67]` Some errors have detailed explanations: E0277, E0658. For more information about an error, try `rustc --explain E0277`. |