1use serde::de::{Deserialize, Deserializer, Error, Unexpected, Visitor};
2use serde::ser::{Serialize, Serializer};
3use std::fmt::{self, Debug, Display};
4
5#[derive(#[automatically_derived]
impl ::core::marker::Copy for Id { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Id {
    #[inline]
    fn clone(&self) -> Id {
        let _: ::core::clone::AssertParamIsClone<u64>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::default::Default for Id {
    #[inline]
    fn default() -> Id { Id { id: ::core::default::Default::default() } }
}Default, #[automatically_derived]
impl ::core::cmp::Eq for Id {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<u64>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for Id {
    #[inline]
    fn eq(&self, other: &Id) -> bool { self.id == other.id }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Ord for Id {
    #[inline]
    fn cmp(&self, other: &Id) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.id, &other.id)
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialOrd for Id {
    #[inline]
    fn partial_cmp(&self, other: &Id)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.id, &other.id)
    }
}PartialOrd, #[automatically_derived]
impl ::core::hash::Hash for Id {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
        ::core::hash::Hash::hash(&self.id, state)
    }
}Hash)]
6pub struct Id {
7    id: u64,
8}
9
10impl Id {
11    pub const NULL: Id = Id { id: 0 };
12}
13
14impl Display for Id {
15    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
16        formatter.write_fmt(format_args!("0x{0:x}", self.id))write!(formatter, "0x{:x}", self.id)
17    }
18}
19
20impl Debug for Id {
21    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
22        formatter.write_fmt(format_args!("Id({0})", self))write!(formatter, "Id({})", self)
23    }
24}
25
26impl<'de> Deserialize<'de> for Id {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
28    where
29        D: Deserializer<'de>,
30    {
31        struct IdVisitor;
32
33        impl<'de> Visitor<'de> for IdVisitor {
34            type Value = Id;
35
36            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
37                formatter.write_str("clang syntax tree node id")
38            }
39
40            fn visit_str<E>(self, string: &str) -> Result<Self::Value, E>
41            where
42                E: Error,
43            {
44                string
45                    .strip_prefix("0x")
46                    .and_then(|hex| u64::from_str_radix(hex, 16).ok())
47                    .map(|id| Id { id })
48                    .ok_or_else(|| E::invalid_value(Unexpected::Str(string), &self))
49            }
50        }
51
52        deserializer.deserialize_str(IdVisitor)
53    }
54}
55
56impl Serialize for Id {
57    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
58    where
59        S: Serializer,
60    {
61        serializer.collect_str(self)
62    }
63}