Expand description
§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
Modules§
- idx
- idx_
enumerate - idx_
range - This is a wrapper around
core::ops::Range
. - index_
array - index_
array_ vec arrayvec
- index_
hash_ map indexmap
- index_
hash_ set indexmap
- index_
slice - index_
slice_ index - index_
small_ vec smallvec
- index_
vec alloc
- index_
vec_ deque alloc
- nonmax
nonmax
- Integers with a niche value based on
NonZero
, allowing for better enum layout optimizations.
Macros§
- enum_
index_ array - Create a
EnumIndexArray
containing the arguments. - idx_
newtype - Declarative alternative to
#[derive(IdxNewtype)]
. - index_
array - Create a
IndexArray
containing the arguments. - index_
array_ vec arrayvec
- Create an
IndexArrayVec
containing the arguments. - index_
hash_ map indexmap
- Create an
IndexHashMap
containing the arguments. - index_
hash_ set indexmap
- Create an
IndexHashSet
containing the arguments. - index_
small_ vec smallvec
- Create an
IndexSmallVec
containing the arguments. - index_
vec alloc
- Create an
IndexVec
containing the arguments. - index_
vec_ deque alloc
- Create an
IndexVecDeque
containing the arguments.
Structs§
- IdxRange
- IdxRange
Inclusive - Index
Array - Index
Array Vec arrayvec
- Index
Hash Map indexmap
- Index
Hash Set indexmap
- Index
Slice - Index
Small Vec smallvec
- Index
Vec alloc
- Index
VecDeque alloc
- NonMax
nonmax
- Generic
NonMax
Traits§
Type Aliases§
- Enum
Index Array - Helper to construct
IndexArray<E, T, { <E as IdxEnum>::COUNT } >
.
Derive Macros§
- Idx
derive
- For structs this is equivalent to
#[derive(IdxNewtype)]
, for enums to#[derive(IdxEnum)]
. - IdxEnum
derive
- Implements the following traits:
- IdxNewtype
derive
- Implements the following traits: