oxilean_kernel/name/
name_traits.rs1use super::types::Name;
14
15impl std::fmt::Display for Name {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 match self {
18 Name::Anonymous => write!(f, "_"),
19 Name::Str(parent, s) => {
20 if parent.is_anonymous() {
21 write!(f, "{s}")
22 } else {
23 write!(f, "{parent}.{s}")
24 }
25 }
26 Name::Num(parent, n) => {
27 if parent.is_anonymous() {
28 write!(f, "{n}")
29 } else {
30 write!(f, "{parent}.{n}")
31 }
32 }
33 }
34 }
35}
36
37impl PartialOrd for Name {
38 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
39 Some(self.cmp(other))
40 }
41}
42
43impl Ord for Name {
44 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
45 self.to_string().cmp(&other.to_string())
46 }
47}