1use core::{
6 cmp::Ordering,
7};
8
9#[derive(Debug, Eq, PartialEq, Ord, Hash)]
13pub struct Remote {
14
15 name: String,
16 url: String,
17
18}
19
20impl Remote {
21
22 pub (crate) fn new(name: String, url: String) -> Self {
24 Self {
25 name,
26 url,
27 }
28 }
29
30 pub fn name(&self) -> &str {
32 &self.name
33 }
34
35 pub fn url(&self) -> &str {
37 &self.url
38 }
39
40 fn is_local(&self) -> bool {
42 self.url.starts_with("/") || self.url.starts_with("file:///")
43 }
44
45}
46
47impl PartialOrd for Remote {
48
49 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
50 let self_is_local = self.is_local();
51 let other_is_local = other.is_local();
52
53 let result = if (self_is_local && other_is_local) || (self_is_local == false && other_is_local == false) {
54 self.name.to_lowercase().cmp(&other.name.to_lowercase())
55 } else if self_is_local {
56 Ordering::Less
57 } else {
58 Ordering::Greater
59 };
60
61 Some(result)
62 }
63
64}