Crate idbag

Source
Expand description

An id bag is conceptually a bag that initially contains (all) intger values of the type of the bag. An application can request to allocate an id from the bag, which behaves like the identifier has been taken out of the bag. Once the id is dropped its integer will automatically be returned to the bag and be available for allocation again.

Allocated identifier objects are hashable and derefernces to its internal integer value.

§Introductionary example

use idbag::IdBagU32;

// Create a new id bag.
let idbag = IdBagU32::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);

§Assigned integer semantics

The assigned integer increases by one each time a new id has been allocated and wraps around at its maximum value.

Structs§

ArcIdU8
An atomically referenced counted version of IdU8.
ArcIdU16
An atomically referenced counted version of IdU16.
ArcIdU32
An atomically referenced counted version of IdU32.
ArcIdU64
An atomically referenced counted version of IdU64.
ArcIdUsize
An atomically referenced counted version of IdUsize.
IdBagU8
A collection of allocatable u8 integers.
IdBagU16
A collection of allocatable u16 integers.
IdBagU32
A collection of allocatable u32 integers.
IdBagU64
A collection of allocatable u64 integers.
IdBagUsize
A collection of allocatable usize integers.
IdU8
An allocated u8 identifier.
IdU16
An allocated u16 identifier.
IdU32
An allocated u32 identifier.
IdU64
An allocated u64 identifier.
IdUsize
An allocated usize identifier.
InnerBagU8
Internal representation of the IdBagU8.
InnerBagU16
Internal representation of the IdBagU16.
InnerBagU32
Internal representation of the IdBagU32.
InnerBagU64
Internal representation of the IdBagU64.
InnerBagUsize
Internal representation of the IdBagUsize.