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
47
48
49
50
51
52
53
54
55
56
57
58
pub mod type_declarations;
pub mod type_references;
use std::sync::atomic::{AtomicU16, Ordering};
use derive_debug_extras::DebugExtras;
static TYPE_COUNTER: AtomicU16 = AtomicU16::new(1);
#[derive(PartialEq, Eq, Clone, Copy, DebugExtras, Hash)]
pub struct TypeId(u16);
impl TypeId {
pub fn new() -> Self {
TypeId(TYPE_COUNTER.fetch_add(1, Ordering::SeqCst))
}
pub const fn new_from_id(id: u16) -> Self {
TypeId(id)
}
#[doc(hidden)]
pub fn unwrap_identifier(self) -> u16 {
self.0
}
pub const NULL: Self = Self(0);
}
#[cfg(feature = "self-rust-tokenize")]
impl self_rust_tokenize::SelfRustTokenize for TypeId {
fn append_to_token_stream(
&self,
token_stream: &mut self_rust_tokenize::proc_macro2::TokenStream,
) {
token_stream.extend(self_rust_tokenize::quote!(TypeId::new()))
}
}