Skip to main content

oxilean_kernel/name/
name_traits.rs

1//! # Name - Trait Implementations
2//!
3//! This module contains trait implementations for `Name`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//! - `PartialOrd`
9//! - `Ord`
10//!
11//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
12
13use 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}