2 unstable releases
Uses old Rust 2015
0.2.0 | Jun 12, 2017 |
---|---|
0.1.0 | Jun 11, 2017 |
#2997 in Rust patterns
27KB
700 lines
Sorted
A Rust library that provides compile time contracts for sorted sequences.
Distributed under the MIT license.
Status
This library is currently being drafted and is not fit for any use at this time.
Reasoning
By limiting sorted types to operations that keeps the sorting order it's possible to give guarantees at compile time. Even different kinds of sort ordering can be typed and forbids collections sorted by different keys or comparisons to be mixed.
Why
If you're dealing with a lot of sorted and unsorted arrays, vectors or iterators in a lot of places in your code it can be easy to slip up and add an element in the wrong place or use an unsorted list where a sorted one is required. Compile time guarantees helps you avoid bugs and declare intentions in those cases.
That said, this library won't provide any actual functionality to your code, except a few convenience methods that keeps the sorted contract. If you're not holding array types sorted for any length of time or bigger amounts, this library is probably overkill.
How
This library implements a number of constraint type wrappers that restricts the mutable operations of Vec and slices to operations that retains the sorted order. Non-mut operations are still provided via Deref. These sorted types can only be created by sorting a regular sequence or copying another sorted type.
Examples
Look at tests/usage.rs on how to use the sorted types.