use core::num::Wrapping;
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
pub struct Handle(pub(crate) u32);
impl core::fmt::Debug for Handle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#08x}", self.0)
}
}
#[derive(Debug)]
pub struct HandleGenerator {
next_id: Wrapping<u32>,
}
impl HandleGenerator {
pub const fn new(offset: u32) -> Self {
Self {
next_id: Wrapping(offset),
}
}
pub fn generate(&mut self) -> Handle {
let id = self.next_id;
self.next_id += 1;
Handle(id.0)
}
}