Crate indexland

Source
Expand description

§Indexland

githubgithub-buildcrates-iomsrvdocs-rs

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

§License

MIT

Modules§

idx
idx_enumerate
idx_range
This is a wrapper around core::ops::Range.
index_array
index_array_vecarrayvec
index_hash_mapindexmap
index_hash_setindexmap
index_slice
index_slice_index
index_small_vecsmallvec
index_vecalloc
index_vec_dequealloc
nonmaxnonmax
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_vecarrayvec
Create an IndexArrayVec containing the arguments.
index_hash_mapindexmap
Create an IndexHashMap containing the arguments.
index_hash_setindexmap
Create an IndexHashSet containing the arguments.
index_small_vecsmallvec
Create an IndexSmallVec containing the arguments.
index_vecalloc
Create an IndexVec containing the arguments.
index_vec_dequealloc
Create an IndexVecDeque containing the arguments.

Structs§

IdxRange
IdxRangeInclusive
IndexArray
IndexArrayVecarrayvec
IndexHashMapindexmap
IndexHashSetindexmap
IndexSlice
IndexSmallVecsmallvec
IndexVecalloc
IndexVecDequealloc
NonMaxnonmax
Generic NonMax

Traits§

Idx
IdxEnum
IdxNewtype

Type Aliases§

EnumIndexArray
Helper to construct IndexArray<E, T, { <E as IdxEnum>::COUNT } >.

Derive Macros§

Idxderive
For structs this is equivalent to #[derive(IdxNewtype)], for enums to #[derive(IdxEnum)].
IdxEnumderive
Implements the following traits:
IdxNewtypederive
Implements the following traits: