slice-group-by
Fast Rust iterators that split slices and strings into contiguous groups
Repository Health
Technical Analysis
slice-group-by is a Rust library that provides group_by-style iterators for slices and string slices, inspired by Haskell’s groupBy. Given a comparison predicate, it yields contiguous subslices whose adjacent elements satisfy the predicate, so runs of equal or related items can be processed as groups.
Unlike iterator-adapter approaches, it operates directly on slice and str, which keeps data access local and fast. It ships multiple traversal strategies (linear, binary, and exponential search), supports mutable groups, iterating from the end, and works in no_std environments.
What You Get
group_by-style iterators oversliceandstr- Linear, binary, and exponential search strategies for different data shapes
- Mutable grouping iterators for in-place processing
- Reverse iteration to yield groups starting from the end
no_stdsupport with an optionalstdfeature
Common Use Cases
- Splitting a sorted slice into runs of equal keys for aggregation
- Grouping characters of a string into contiguous segments
- Iterating groups from the end of a slice
Under The Hood
Architecture - The crate is organized by strategy: linear_group/, binary_group/, exponential_group/, and linear_str_group/ each implement a family of grouping iterators, tied together by extension traits (GroupBy, GroupByMut, and str equivalents) exported from lib.rs. Each iterator walks a slice or str and yields contiguous subslices determined by the user’s predicate, with mutable and reverse variants alongside the immutable ones.
Tech Stack - Written in Rust (edition 2018) with zero runtime dependencies; only rand is used as a dev-dependency for tests. It declares the algorithms crates.io category and gates the standard library behind a default std feature plus an optional nightly feature for extra optimizations.
Code Quality - Despite its small scope the crate is thoroughly structured, with separate modules per algorithm and a substantial test surface (the single language is Rust across ~100KB, much of it tests and doctests). It is stable and mature; development has been quiet since 2023 because the API is essentially complete.
API Design - The ergonomics mirror the standard library: call slice.linear_group_by(|a, b| ...) or the binary/exponential variants and iterate the resulting groups, exactly like slice::sort_by. Method names communicate both the operation and the search strategy, and the README documents each with runnable examples, so adoption is straightforward for anyone familiar with Rust iterators.