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
. - ArcId
U16 - An atomically referenced counted version of
IdU16
. - ArcId
U32 - An atomically referenced counted version of
IdU32
. - ArcId
U64 - An atomically referenced counted version of
IdU64
. - ArcId
Usize - An atomically referenced counted version of
IdUsize
. - IdBagU8
- A collection of allocatable
u8
integers. - IdBag
U16 - A collection of allocatable
u16
integers. - IdBag
U32 - A collection of allocatable
u32
integers. - IdBag
U64 - A collection of allocatable
u64
integers. - IdBag
Usize - 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. - Inner
BagU8 - Internal representation of the
IdBagU8
. - Inner
BagU16 - Internal representation of the
IdBagU16
. - Inner
BagU32 - Internal representation of the
IdBagU32
. - Inner
BagU64 - Internal representation of the
IdBagU64
. - Inner
BagUsize - Internal representation of the
IdBagUsize
.