Pencil-Box
A simple and efficient Rust utility to split slices into fixed-size chunks, returning owned Vec<T> chunks.
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
Replace
"0.1.0"with the latest version from crates.io
๐ Usage
use chunk;
๐งฉ Function Behavior
The chunk function behaves as follows:
- โ
Returns an error if
chunk_size == 0 - โ Returns an empty vector if the input slice is empty
- โ
Returns a single chunk containing all elements if
chunk_size >= array.len() - โ
Returns multiple chunks of up to
chunk_sizeelements otherwise
Each chunk is a cloned Vec<T>, preserving data integrity and independence.
๐งช Test Coverage
The implementation is covered by comprehensive unit tests, including:
- โ
Primitive types:
i32,bool, etc. - โ
Strings and owned
String - โ
Structs (
Clone + PartialEq) - โ
Enums (e.g.,
Status::Ok,Status::Error) - โ
Nested collections (e.g.,
Vec<Vec<T>>) - โ
Edge cases:
- Empty input
chunk_size == 0(returns error)chunk_size >= input.len()(returns single chunk)
To run tests:
๐ Safety
- 100% safe Rust (
#![forbid(unsafe_code)]) - No
unsafeblocks used - Pure functional logic
๐ License
This project is dual-licensed under either:
- MIT OR
- Apache 2.0
You may freely choose either license.
๐ค Contributing
Contributions, bug reports, and feature requests are welcome.
Please open an issue or submit a pull request.