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