Skip to content

subscriber: Replace OFF with None in empty Vec max_level_hint#3564

Open
nicopap wants to merge 1 commit into
tokio-rs:mainfrom
npapale:empty-vec-layer-nonfiltering
Open

subscriber: Replace OFF with None in empty Vec max_level_hint#3564
nicopap wants to merge 1 commit into
tokio-rs:mainfrom
npapale:empty-vec-layer-nonfiltering

Conversation

@nicopap

@nicopap nicopap commented Jun 12, 2026

Copy link
Copy Markdown

The expected behavior of adding an empty Vec as Layer is that it does nothing. Right now, it adds a LevelFilter::OFF rule, thus supressing other layers.

This change makes max_level_hint return None, which doesn't supress other layers, following expected behavior.

Motivation

Solution

We return None when the vec is empty.

Details

The one-liner: cute solution, but might not be obvious how it works at first glance:

  • We want the highest level filter for LevelFilter, but we want the None case to be even higher priority than other.
  • Problem: the Ord impl of Option makes None the lowest possible value. Solution: We use min instead of max!
  • Problem: But then our ordering is invalid for LevelFilter. Solution: We use .map(Reverse) so that min for LevelFilter is equivalent to max!
  • We just have to unwrap the whole thing at the end with Some(x??.0)

The expected behavior of adding an empty Vec as Layer is that it does
nothing. Right now, it adds a LevelFilter::OFF rule, thus supressing
other layers.

This change makes max_level_hint return None, which doesn't supress
other layers, following expected behavior.

* Fixes tokio-rs#3563
* This is a breaking change (no API change, but observable behavior)
@nicopap nicopap requested review from a team, hawkw and hds as code owners June 12, 2026 11:39
@nicopap

nicopap commented Jun 29, 2026

Copy link
Copy Markdown
Author

Is there some actions I should be doing, or is it just that the review bandwidth is saturated?

Asking not out of frustration (the maintainers should go at their own pace and I'm not entitled to anything), but rather out of concern that I'm not making everything to make the reviewer's job easier.

@nicopap nicopap changed the title Replace OFF with None in empty Vec max_level_hint subscriber: Replace OFF with None in empty Vec max_level_hint Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should <Vec as Layer>::max_level_hint be OFF when Vec is empty?

1 participant