271 Commits

Author SHA1 Message Date
Erick Tryzelaar
c5ff797dcf
udp: document and shrink some unsafe blocks (#4655)
This documents why it is safe to convert `bytes::UninitSlice` to `&mut
[MaybeUninit<u8>]`, and shrinks one of the unsafe blocks to make these
functions easier to audit.
2022-05-05 19:48:39 +00:00
Eliza Weisman
d456706528
util: implement JoinMap (#4640)
## Motivation

In many cases, it is desirable to spawn a set of tasks associated with
keys, with the ability to cancel them by key. As an example use case for
this sort of thing, see Tower's [`ReadyCache` type][1].

Now that PR #4530 adds a way of cancelling tasks in a
`tokio::task::JoinSet`, we can implement a map-like API based on the
same `IdleNotifiedSet` primitive.

## Solution

This PR adds an implementation of a `JoinMap` type to
`tokio_util::task`, using the `JoinSet` type from `tokio::task`, the
`AbortHandle` type added in #4530, and the new task IDs added in #4630.

Individual tasks can be aborted by key using the `JoinMap::abort`
method, and a set of tasks whose key match a given predicate can be
aborted using `JoinMap::abort_matching`.

When tasks complete, `JoinMap::join_one` returns their associated key
alongside the output from the spawned future, or the key and the
`JoinError` if the task did not complete successfully.

Overall, I think the way this works is pretty straightforward; much of
this PR is just API boilerplate to implement the union of applicable
APIs from `JoinSet` and `HashMap`. Unlike previous iterations on the
`JoinMap` API (e.g. #4538), this version is implemented entirely in
`tokio_util`, using only public APIs from the `tokio` crate. Currently,
the required `tokio` APIs are unstable, but implementing `JoinMap` in
`tokio-util` means we will never have to make stability commitments for
the `JoinMap` API itself.

[1]: https://github.com/tower-rs/tower/blob/master/tower/src/ready_cache/cache.rs

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-04-26 17:25:48 +00:00
Paolo Barbolini
f8a6cf49cd
tracing: don't require default tracing features (#4592) 2022-04-03 11:30:07 +02:00
Dirkjan Ochtman
a05135a4f8
chore: prepare tokio-util 0.7.1 release (#4521) 2022-03-28 14:34:11 +02:00
b-naber
f84c4d596a
io: add StreamReader::into_inner_with_chunk (#4559) 2022-03-23 20:41:09 +01:00
Gus Wynn
413c812ac8
util: switch tokio-util from log to tracing (#4539) 2022-02-26 12:47:04 +01:00
Nikolai Vazquez
3f508d1622
codec: add length_field_type to LengthDelimitedCodec builder (#4508) 2022-02-23 11:46:52 +01:00
Takuya Kajiwara
503ae34cd3
util: fix import path of CancellationToken in example code (#4520) 2022-02-23 11:46:35 +01:00
b-naber
9a3ce91ef5
util: fix waker update condition in CancellationToken (#4497)
There was a missing exclamation mark in the condition we used to test
whether we need a waker update in `check_for_cancellation`.
2022-02-14 13:18:10 -08:00
Dirkjan Ochtman
69f135ed60
util: bump tokio dependency to 1.6 to satisfy minimal versions (#4490) 2022-02-12 10:02:07 +01:00
Toby Lawrence
e7a0da60cd
chore: prepare tokio-util 0.7.0 (#4486) 2022-02-10 12:23:58 -05:00
Kestrer
9c688ecdc3
util: add lifetime parameter to ReusableBoxFuture (#3762)
Co-authored-by: Toby Lawrence <toby@nuclearfurnace.com>
2022-02-09 14:29:21 -05:00
Toby Lawrence
52fb93dce9
sync: refactored PollSender<T> to fix a subtly broken Sink<T> implementation (#4214)
Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2022-02-09 12:09:04 -05:00
Benjamin Saunders
cf38ba627a
util: remove error case from the infallible DelayQueue::poll_elapsed (#4241) 2022-02-08 21:07:33 -05:00
Sunyeop Lee
0b05ef638d
codec: implement Encoder<BytesMut> for BytesCodec (#4465) 2022-02-08 09:11:24 -05:00
Carl Lerche
49fff47111
chore: increase MSRV to 1.49. (#4457)
Rust 1.49 was released on December 31, 2020, which meets our MSRV policy
of a minimum of 6 months.
2022-01-31 13:26:12 -08:00
Carl Lerche
986b88b3f1
chore: update year in LICENSE files (#4429) 2022-01-27 13:36:21 -08:00
Mark Drobnak
257053e40b
util: add spawn_pinned (#3370) 2022-01-27 15:26:09 +01:00
Cecile Tonglet
8f77ee8609
net: add generic trait to combine UnixListener and TcpListener (#4385) 2022-01-27 15:13:37 +01:00
Luiz Carlos
2a5071fc2d
feat: implement Framed::map_codec (#4427) 2022-01-27 12:37:30 +01:00
b-naber
c800deaacc
util: add shrink_to_fit and compact methods to DelayQueue (#4170) 2022-01-09 12:41:30 +01:00
Tom Dohrmann
4a12163d7c
util: add mutable reference getters for codecs to pinned Framed (#4372) 2022-01-03 22:21:43 +01:00
David Kleingeld
dc1894105b
codec: improve Builder::max_frame_length docs (#4352) 2021-12-28 15:08:37 +01:00
Toby Lawrence
4b6bb1d9a7
chore(util): start v0.7 release cycle (#4313)
* chore(util): start v0.7 release cycle

Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2021-12-10 13:16:17 -05:00
Taiki Endo
1a423b3322
chore: remove doc URL from Cargo.toml (#4251)
https://doc.rust-lang.org/cargo/reference/manifest.html#the-documentation-field

> If no URL is specified in the manifest file, crates.io will
> automatically link your crate to the corresponding docs.rs page.
2021-11-23 11:53:32 +01:00
Taiki Endo
a8b662f643
ci: upgrade to new nightly (#4268) 2021-11-23 19:29:57 +09:00
Taiki Endo
cf3206842c
chore: bump MSRV to 1.46 (#4254) 2021-11-23 12:09:24 +09:00
Alice Ryhl
aa03622cf3
chore: prepare tokio-util 0.6.9 (#4199) 2021-10-29 18:34:23 +02:00
Bhargav
0c68b89452
codec: update stream impl for Framed to return None after Err (#4166) 2021-10-26 16:56:15 +02:00
Alice Ryhl
e04b5be1f5
time: update deadline on removal in DelayQueue (#4178) 2021-10-22 20:34:36 +02:00
Colin Walters
2734fa9a85
util/io: add SyncIoBridge (#4146) 2021-10-22 18:46:29 +02:00
Nylonicious
a73428252b
util: update README (#4099) 2021-09-10 08:55:03 +02:00
Pablo Sichert
98e78a6f7b
codec: implement Clone for LengthDelimitedCodec (#4089) 2021-09-07 13:51:35 +02:00
Toby Lawrence
01a6feb0dc
chore: prepare tokio-util v0.6.8 (#4087)
Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2021-09-03 10:57:27 -04:00
Jorge Leitao
e31e06c5c2
compat: added AsyncSeek compat (#4078) 2021-09-03 08:54:40 +02:00
ttys3
d0dd74a058
io: add with_capacity for ReaderStream (#4086) 2021-09-02 09:53:23 +02:00
Toby Lawrence
23b0aee5dd
tokio-util: expose key used in DelayQueue's Expired (#4081)
Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2021-08-31 17:09:10 -04:00
LinkTed
8198ef3881
chore: fix clippy warnings (#4017) 2021-08-03 10:50:40 +02:00
Alice Ryhl
8f27c04a9e
codec: remove unnecessary doc(cfg(...)) (#3989) 2021-07-26 12:32:24 +02:00
Blas Rodriguez Irizar
4818c2ed05
fs: document performance considerations (#3920) 2021-07-06 16:25:13 +02:00
Taiki Endo
08ed41f339
chore: fix typos (#3907) 2021-07-01 02:06:56 +09:00
Mikail Bagishov
d35ff7064f
sync: add drop guard for cancellation token (#3839) 2021-06-28 12:34:58 +02:00
Taiki Endo
9d8b37d51a
macros: suppress clippy::default_numeric_fallback lint in generated code (#3831) 2021-06-02 18:16:23 +09:00
Aaron Taner
ce9ca45c92
doc: fix invalid #[doc(inline)] warnings on latest nightly. (#3788)
This commit fixed issue #3787 by removing [doc(inline)] from
macro `cfg_macros` and added proper #[doc(inline)] attributes
to `pub use` items inside `cfg_macros` calls.

It's probably not `cfg_macros`s responsibility to inlining public
macros, though it's conveninent to do so. Notice that in lib.rs:

cfg_macros! {
    /// Implementation detail of the `select!` macro. This macro is **not**
    /// intended to be used as part of the public API and is permitted to
    /// change.
    #[doc(hidden)]
    pub use tokio_macros::select_priv_declare_output_enum;

    ...
}

`#[doc(hidden)]` and `#[doc(inline)]` are conflict with each other
in the sense of correctness.

Fixes: #3787
2021-05-18 01:28:17 +09:00
Alice Ryhl
deb1f98125
chore: prepare tokio-util v0.6.7 (#3784) 2021-05-14 18:22:08 +02:00
Chris Moore
05c3cf3a0a
util: impl AsRawFd/AsRawHandle for Compat<T> (#3765) 2021-05-08 12:55:04 +02:00
John-John Tedro
2c5dc83019
cargo: path dependencies for all tokio things (#3764) 2021-05-08 12:54:30 +02:00
Taiki Endo
c4b6b130f3
chore: bump nightly to nightly-2021-04-25 (#3754) 2021-05-05 17:39:17 +02:00
Kai Mast
55c5d12451
util: require full feature in tokio-util tests (#3636) 2021-05-05 18:21:25 +09:00
Evan Cameron
9eeec039f2
util: make UdpFramed take Borrow<UdpSocket> (#3451) 2021-04-14 20:16:23 +02:00