yazi/yazi-sftp/src/id.rs
2025-09-14 02:50:28 +08:00

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;
}
}
}
}