Crate idbag

source ·
Expand description

The IdBag is conceptually a bag that initially contains (all) u32 values. An application can request to allocate an Id that will contain a u32 value taken from the bag. Once the Id is dropped its u32 will automatically be returned to the bag and be available for allocation again.

Id objects are hashable and transparently maps to its internal u32. They can also be

§Introductionary example

use idbag::IdBag;

// Create a new id heap.
let idbag = IdBag::new();

// Allocate an id; first id will have a value of 1.
let id = idbag.alloc();
assert_eq!(id.val(), 1);

// The id's drop handler returns 1 to the idbag
drop(id);

// Allocate another id; next id will have a value of 2.
let id = idbag.alloc();
assert_eq!(id.val(), 2);

// The id's drop handler returns 2 to the idbag
drop(id);

Structs§

  • An atomically referenced counted version of Id.
  • Representation of an allocated identifier.
  • A collection of all u32 integers that can be allocated.
  • Internal representation of the IdBag.