blob: 480c31b69e0fe8401d157d4bca8450326003cef0 [file] [log] [blame]
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::cmp::Ordering;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Path {
name: String,
}
impl Path {
pub fn new<T>(name: T) -> Self
where
String: From<T>,
{
Self { name: name.into() }
}
pub fn name(&self) -> &str {
&self.name
}
pub fn replace_self_with(&mut self, path: &Self) -> bool {
if self.name() != "Self" {
return false;
}
*self = path.clone();
true
}
}
impl PartialOrd for Path {
fn partial_cmp(&self, other: &Path) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Path {
fn cmp(&self, other: &Path) -> Ordering {
self.name.cmp(&other.name)
}
}
impl fmt::Display for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)
}
}