1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use core::cell::Cell;
use std::thread_local;
thread_local! {
pub static COUNT: Cell<usize> = Cell::new(0);
}
#[inline]
pub fn set_count(count: usize) {
COUNT.with(|c| c.set(count));
}
#[inline]
pub fn get_count() -> usize {
COUNT.with(|c| c.get())
}
#[inline]
pub fn bump_count() {
COUNT.with(|c|
{
let count = c.get();
c.set(count + 1);
}
)
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Ident {
pub idx: usize,
pub len: usize,
}
impl Ident {
pub fn new(len: usize) -> Ident {
crate::COUNT.with(|count| Ident {
idx: count.get(),
len,
})
}
}