pub struct IdBagU32(/* private fields */);Expand description
A collection of allocatable u32 integers.
Implementations§
Source§impl IdBagU32
impl IdBagU32
Sourcepub const fn with_inner(inner: Arc<Mutex<InnerBagU32>>) -> Self
pub const fn with_inner(inner: Arc<Mutex<InnerBagU32>>) -> Self
Create a new id generator using a pre-existing set.
This is useful when multiple IdBag instances should share the
same inner context. The practical implication of this is that the
IdBag’s that share the same inner context will not yield overlapping
identifier values.
use idbag::IdBagU32;
let idbag1 = IdBagU32::new();
let idbag2 = IdBagU32::with_inner(idbag1.clone_inner());
let id1 = idbag1.alloc();
assert_eq!(id1.val(), 1);
let id2 = idbag2.alloc();
assert_eq!(id2.val(), 2);Sourcepub fn clone_inner(&self) -> Arc<Mutex<InnerBagU32>>
pub fn clone_inner(&self) -> Arc<Mutex<InnerBagU32>>
Return a clone of the internal id collection.
Sourcepub fn alloc(&self) -> IdU32
pub fn alloc(&self) -> IdU32
Allocate a new identifier.
use idbag::IdBagU32;
let idbag = IdBagU32::new();
let id = idbag.alloc();
assert_eq!(id.val(), 1);
let id = idbag.alloc();
assert_eq!(id.val(), 2);§Desgin flaws
This function will hang if all the id’s have been exhausted.
Sourcepub fn alloc_id(&self, id: u32) -> Option<IdU32>
pub fn alloc_id(&self, id: u32) -> Option<IdU32>
Allocate a specific id, if available.
use idbag::IdBagU32;
let idbag = IdBagU32::new();
let Some(id) = idbag.alloc_id(42) else {
panic!("Unexpectedly unable to allocate id 42");
};
assert_eq!(id.val(), 42);
let id = idbag.alloc_id(42);
assert_eq!(id, None);Trait Implementations§
Auto Trait Implementations§
impl Freeze for IdBagU32
impl !RefUnwindSafe for IdBagU32
impl Send for IdBagU32
impl Sync for IdBagU32
impl Unpin for IdBagU32
impl !UnwindSafe for IdBagU32
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more