3 unstable releases
new 0.2.1 | Mar 7, 2025 |
---|---|
0.2.0 | Mar 7, 2025 |
0.1.0 | Feb 22, 2025 |
#1078 in Data structures
380 downloads per month
120KB
3.5K
SLoC
Indexland
Wrappers for common collection types based on newtype indices. Increased type safety and code readability without runtime overhead.
Newtype Indices
use indexland::{Idx, IndexVec};
#[derive(Idx)]
struct NodeId(u32);
struct Node<T> {
prev: NodeId,
next: NodeId,
data: T,
}
struct DoublyLinkedList<T> {
nodes: IndexVec<NodeId, Node<T>>,
}
Enums as Indices
use indexland::{enum_index_array, EnumIndexArray, Idx};
#[derive(Idx)]
enum PrimaryColor {
Red,
Green,
Blue,
}
const COLOR_MAPPING: EnumIndexArray<PrimaryColor, u32> = enum_index_array![
PrimaryColor::Red => 0xFF0000,
PrimaryColor::Green => 0x00FF00,
PrimaryColor::Blue => 0x0000FF,
];
let my_color = COLOR_MAPPING[PrimaryColor::Red];
Support for most common Array Based Collections
IndexSlice<I, T>
wrapping&[T]
IndexArray<I, T, LEN>
wrapping[T; LEN]
IndexVec<I, T>
wrappingVec<T>
IndexVecDeque<I, T>
wrappingVecDeque<T>
IndexSmallVec<I, T, CAP>
wrappingSmallVec<[T;CAP]>
(Optional)IndexArrayVec<I, T, CAP>
wrappingArrayVec<T, CAP>
(Optional)IndexHashMap<I, K, V>
wrappingIndexMap<K, V>
(Optional)IndexHashSet<I, T>
wrappingIndexSet<T>
(Optional)NonMax<T>
Integer Types for Niche Optimizations (Optional)serde
support for all Collections (Optional)
License
Dependencies
~62–395KB