1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5use std::cmp::Ordering;
6use std::fmt;
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct Path {
10 name: String,
11}
12
13impl Path {
14 pub fn new<T>(name: T) -> Self
15 where
16 String: From<T>,
17 {
18 Self { name: name.into() }
19 }
20
21 pub fn name(&self) -> &str {
22 &self.name
23 }
24
25 pub fn replace_self_with(&mut self, path: &Self) -> bool {
26 if self.name() != "Self" {
27 return false;
28 }
29 *self = path.clone();
30 true
31 }
32}
33
34impl PartialOrd for Path {
35 fn partial_cmp(&self, other: &Path) -> Option<Ordering> {
36 Some(self.cmp(other))
37 }
38}
39
40impl Ord for Path {
41 fn cmp(&self, other: &Path) -> Ordering {
42 self.name.cmp(&other.name)
43 }
44}
45
46impl fmt::Display for Path {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 write!(f, "{}", self.name)
49 }
50}
51