pub struct IdGenerator { /* private fields */ }Expand description
Thread-safe unique ID generator for ARIA attribute cross-references.
Every interactive component needs unique, stable IDs for ARIA attributes
like aria-controls, aria-labelledby, and aria-describedby.
IDs are generated with a configurable prefix and an atomic counter,
producing values like "stratum-btn-001", "stratum-dialog-002".
Implementations§
Source§impl IdGenerator
impl IdGenerator
Sourcepub fn new(prefix: impl Into<String>) -> Self
pub fn new(prefix: impl Into<String>) -> Self
Create a new ID generator with the given prefix.
§Example
use stratum_core::IdGenerator;
let id_gen = IdGenerator::new("btn");
let id = id_gen.next();
assert!(id.starts_with("stratum-btn-"));Sourcepub fn paired(&self) -> (String, String)
pub fn paired(&self) -> (String, String)
Generate a paired set of IDs for label + target relationships.
Returns (label_id, target_id) — useful for aria-labelledby
and aria-controls relationships.
Sourcepub fn group(&self, suffixes: &[&str]) -> Vec<String>
pub fn group(&self, suffixes: &[&str]) -> Vec<String>
Generate a set of related IDs for multi-part components.
For example, a Disclosure needs a trigger ID and content ID.
Sourcepub fn current_count(&self) -> u64
pub fn current_count(&self) -> u64
Get the current counter value (for testing).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for IdGenerator
impl RefUnwindSafe for IdGenerator
impl Send for IdGenerator
impl Sync for IdGenerator
impl Unpin for IdGenerator
impl UnsafeUnpin for IdGenerator
impl UnwindSafe for IdGenerator
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