use core::{
cmp::Ordering,
};
#[derive(Debug, Eq, PartialEq, Ord, Hash)]
pub struct Remote {
name: String,
url: String,
}
impl Remote {
pub fn new(name: String, url: String) -> Self {
Self {
name,
url,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn url(&self) -> &str {
&self.url
}
fn is_local(&self) -> bool {
self.url.starts_with("/") || self.url.starts_with("file:///")
}
}
impl PartialOrd for Remote {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let self_is_local = self.is_local();
let other_is_local = other.is_local();
let result = if (self_is_local && other_is_local) || (self_is_local == false && other_is_local == false) {
self.name.to_lowercase().cmp(&other.name.to_lowercase())
} else if self_is_local {
Ordering::Less
} else {
Ordering::Greater
};
Some(result)
}
}