Pencil-Box
A simple and efficient Rust utility for:
- ๐ฆ Splitting slices into fixed-size chunks with
chunk - ๐ Removing duplicate elements from vectors with
uniqanduniq_performant
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.2"
Replace
"0.1.2"with the latest version from crates.io
๐ Usage
โ๏ธ Chunking Slices
use chunk;
๐งน Deduplicating Vectors
use ;
๐งฉ Function Behavior
chunk
- โ
Returns an error if
chunk_size == 0 - โ Returns an empty vector if the input slice is empty
- โ
Returns a single chunk if
chunk_size >= array.len() - โ
Returns multiple chunks of up to
chunk_sizeelements otherwise
Each chunk is cloned into an owned Vec<T>.
uniq
- โ
Uses the standard
HashSetto remove duplicates in-place - โ Retains the first occurrence of each element
- โ Preserves relative ordering
- ๐ Best for general-purpose use
uniq_performant
- ๐ Uses
AHashSetfor faster hashing and performance - โ Retains the first occurrence of each element
- โ Preserves relative ordering
- โก Ideal for high-throughput or performance-critical use cases
๐ 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.