Skip to main content

grm/repo/
remote.rs

1use std::{borrow::Cow, fmt};
2
3use crate::config;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct RemoteName(Cow<'static, str>);
7
8impl fmt::Display for RemoteName {
9    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10        write!(f, "{}", self.0)
11    }
12}
13
14impl RemoteName {
15    pub fn new(from: String) -> Self {
16        Self(Cow::Owned(from))
17    }
18
19    pub const fn new_static(from: &'static str) -> Self {
20        Self(Cow::Borrowed(from))
21    }
22
23    pub fn as_str(&self) -> &str {
24        &self.0
25    }
26
27    pub fn into_string(self) -> String {
28        match self.0 {
29            Cow::Borrowed(s) => s.to_owned(),
30            Cow::Owned(s) => s,
31        }
32    }
33}
34
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct RemoteUrl(String);
37
38impl fmt::Display for RemoteUrl {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        write!(f, "{}", self.0)
41    }
42}
43
44impl RemoteUrl {
45    pub fn new(from: String) -> Self {
46        Self(from)
47    }
48
49    pub fn as_str(&self) -> &str {
50        &self.0
51    }
52
53    pub fn into_string(self) -> String {
54        self.0
55    }
56}
57
58#[derive(Debug, PartialEq, Eq)]
59pub enum RemoteType {
60    Ssh,
61    Https,
62    File,
63}
64
65impl From<config::RemoteType> for RemoteType {
66    fn from(value: config::RemoteType) -> Self {
67        match value {
68            config::RemoteType::Ssh => Self::Ssh,
69            config::RemoteType::Https => Self::Https,
70            config::RemoteType::File => Self::File,
71        }
72    }
73}
74
75impl From<RemoteType> for config::RemoteType {
76    fn from(value: RemoteType) -> Self {
77        match value {
78            RemoteType::Ssh => Self::Ssh,
79            RemoteType::Https => Self::Https,
80            RemoteType::File => Self::File,
81        }
82    }
83}