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)
}
}