]> git.lizzy.rs Git - rust.git/blob - src/librustc_session/node_id.rs
Rollup merge of #68469 - ollie27:skip_count, r=sfackler
[rust.git] / src / librustc_session / node_id.rs
1 use rustc_serialize::{Decoder, Encoder};
2 use rustc_span::ExpnId;
3 use std::fmt;
4
5 rustc_index::newtype_index! {
6     pub struct NodeId {
7         ENCODABLE = custom
8         DEBUG_FORMAT = "NodeId({})"
9     }
10 }
11
12 rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
13
14 impl NodeId {
15     pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
16         NodeId::from_u32(expn_id.as_u32())
17     }
18
19     pub fn placeholder_to_expn_id(self) -> ExpnId {
20         ExpnId::from_u32(self.as_u32())
21     }
22 }
23
24 impl fmt::Display for NodeId {
25     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26         fmt::Display::fmt(&self.as_u32(), f)
27     }
28 }
29
30 impl rustc_serialize::UseSpecializedEncodable for NodeId {
31     fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
32         s.emit_u32(self.as_u32())
33     }
34 }
35
36 impl rustc_serialize::UseSpecializedDecodable for NodeId {
37     fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
38         d.read_u32().map(NodeId::from_u32)
39     }
40 }