pub struct IdBagU16(/* private fields */);Expand description
A collection of allocatable u16 integers.
Implementations§
Source§impl IdBagU16
impl IdBagU16
Sourcepub const fn with_inner(inner: Arc<Mutex<InnerBagU16>>) -> Self
pub const fn with_inner(inner: Arc<Mutex<InnerBagU16>>) -> 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::IdBagU16;
let idbag1 = IdBagU16::new();
let idbag2 = IdBagU16::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<InnerBagU16>>
pub fn clone_inner(&self) -> Arc<Mutex<InnerBagU16>>
Return a clone of the internal id collection.
Sourcepub fn alloc(&self) -> IdU16
pub fn alloc(&self) -> IdU16
Allocate a new identifier.
use idbag::IdBagU16;
let idbag = IdBagU16::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: u16) -> Option<IdU16>
pub fn alloc_id(&self, id: u16) -> Option<IdU16>
Allocate a specific id, if available.
use idbag::IdBagU16;
let idbag = IdBagU16::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 IdBagU16
impl !RefUnwindSafe for IdBagU16
impl Send for IdBagU16
impl Sync for IdBagU16
impl Unpin for IdBagU16
impl !UnwindSafe for IdBagU16
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