mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
18 lines
311 B
Rust
18 lines
311 B
Rust
use std::sync::atomic::{AtomicU32, Ordering};
|
|
|
|
pub(super) struct Id(AtomicU32);
|
|
|
|
impl Default for Id {
|
|
fn default() -> Self { Self(AtomicU32::new(1)) }
|
|
}
|
|
|
|
impl Id {
|
|
pub(super) fn next(&self) -> u32 {
|
|
loop {
|
|
let old = self.0.fetch_add(1, Ordering::Relaxed);
|
|
if old != 0 {
|
|
return old;
|
|
}
|
|
}
|
|
}
|
|
}
|