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

Download history 72/week @ 2025-02-16 62/week @ 2025-02-23 246/week @ 2025-03-02

380 downloads per month

MIT license

120KB
3.5K SLoC

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

Dependencies

~62–395KB