| Crates.io | equal-parts |
| lib.rs | equal-parts |
| version | 1.0.3 |
| created_at | 2025-09-08 15:04:38.90095+00 |
| updated_at | 2025-09-18 01:36:11.748134+00 |
| description | An iterator that splits a collection into approximately equal parts. |
| homepage | |
| repository | https://github.com/amchugh/equal-parts |
| max_upload_size | |
| id | 1829380 |
| size | 45,219 |
The equal-parts crate provides the EqualParts trait, which allows you to split slices and vectors into a specified number of approximately equal-sized parts. Approximately means that the difference in size between any two parts is at most one element. When the total number of elements doesn't divide evenly, the larger parts appear first.
use equal_parts::EqualParts;
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let mut iter = data.equal_parts(4);
assert_eq!(iter.next(), Some([1, 2, 3].as_slice())); // 3 elements
assert_eq!(iter.next(), Some([4, 5, 6].as_slice())); // 3 elements
assert_eq!(iter.next(), Some([7, 8].as_slice())); // 2 elements
assert_eq!(iter.next(), Some([9, 10].as_slice())); // 2 elements
assert_eq!(iter.next(), None);
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.