1 use std::num::NonZeroUsize; 2 use std::sync::atomic::{AtomicUsize, Ordering}; 3 next() -> NonZeroUsize4fn next() -> NonZeroUsize { 5 static COUNTER: AtomicUsize = AtomicUsize::new(1); 6 NonZeroUsize::new(COUNTER.fetch_add(1, Ordering::SeqCst)).expect("more than usize::MAX threads") 7 } 8 get() -> NonZeroUsize9pub(crate) fn get() -> NonZeroUsize { 10 thread_local!(static THREAD_ID: NonZeroUsize = next()); 11 THREAD_ID.with(|&x| x) 12 } 13