`std::slice::chunk_by_key` missing - oversight?

There's slice::chunk_by, but no slice::chunk_by_key, which might be helpful because it could:

  • Evaluate the "key" once per element and re-use it for subsequent comparisons.
  • Supply the "key" in addition to the chunk, avoiding re-computing it.

Here is an inefficient implementation to show how this iterator would be used.

I assume there is a reason why there is no in std::slice::chunk_by_key, but I don't see it so far. Or was this an oversight?

You could propose an ACP: Feature lifecycle - Standard library developers Guide

Note that, like all the by_key functions, this would run into slice::sort_by_key has more restrictions than slice::sort_by · Issue #34162 · rust-lang/rust · GitHub.