#indices #stability #structs #stable #structures #mainly #different

stable-id

This crate mainly deals with issuing and maintaining stability of indices

11 unstable releases (3 breaking)

0.4.1 Feb 24, 2023
0.4.0 Feb 24, 2023
0.3.4 Feb 7, 2023
0.3.0 Jan 30, 2023
0.1.1 Jan 19, 2023

#8 in #mainly

Download history 2/week @ 2024-02-26 92/week @ 2024-03-25 3/week @ 2024-04-01

95 downloads per month

MIT/Apache

63KB
1.5K SLoC

Overview

This crate mainly deals with issuing and maintaining stability of indices. It provides 4 structs and each helps in different area. This library was created for my game development endeavor. Not going great on that front as I kept restarting the project. However, I saw these utility structures coming back multiple times so I'm making a crate for them.

installation

cargo add stable-id stable-id-traits derive-stable-id

Documentation

Click here to learn how to use this crate.


lib.rs:

This crate mainly deals with issuing and maintaining stability of indices. It provides 4 structs and each helps in different area.

This library was created for my game development endeavor. Not going great on that front as I kept restarting the project. However, I saw these utility structures coming back multiple times so I'm making a crate for them.

In version 0.2.0, you can supply custom Id tuple structs that are based on unsigned integers (from 8bit to 64bits). The id type needs to be derived with the following:

// Minimal needed for all traits that are introduced by this crate.
#[derive(derive_stable_id::StableId)]
struct Id(u8);


// These are needed under normal circumstances.
#[derive(derive_stable_id::StableId)]
struct Id32(u32);

let x: stable_id::Eids<Id32> = Default::default();
let x: stable_id::Sequence<Id32> = Default::default();
let x: stable_id::SparseEntities<Id32, String> = Default::default();
let x: stable_id::Entities<Id32, String> = Default::default();
let x: stable_id::Tec<Id32, String> = Default::default();

Use cases

Struct Type Suggestion Description
Eids Id Dense data You want a way to create ids, and do care about recovering ids.
Sequence Id Sparse data You want a way to create ids, and don't care about recovering ids, but you don't want to use the HashMap-based Entities struct.
Entities Collection Dense data The go-to collection of this library.
SparseEntities Collection Sparse data You want mix sequence (ids not recycled) and HashMap together.
[Tec] Collection Dense data You want to use a vec to store data, but need constant entity removal. [Tec] reclaims the spaces for you as you insert more new items.

Dependencies

~1.5MB
~35K SLoC