git_url/
scheme.rs

1/// A scheme or protocol for use in a [`Url`][crate::Url].
2///
3/// It defines how to talk to a given repository.
4#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
5#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
6#[allow(missing_docs)]
7pub enum Scheme {
8    /// A local resource that is accessible on the current host.
9    File,
10    /// A git daemon, like `File` over TCP/IP.
11    Git,
12    /// Launch `git-upload-pack` through an `ssh` tunnel.
13    Ssh,
14    /// Use the HTTP protocol to talk to git servers.
15    Http,
16    /// Use the HTTPS protocol to talk to git servers.
17    Https,
18    /// Any other protocol or transport that isn't known at compile time.
19    ///
20    /// It's used to support plug-in transports.
21    Ext(String),
22}
23
24impl<'a> From<&'a str> for Scheme {
25    fn from(value: &'a str) -> Self {
26        match value {
27            "ssh" => Scheme::Ssh,
28            "file" => Scheme::File,
29            "git" => Scheme::Git,
30            "http" => Scheme::Http,
31            "https" => Scheme::Https,
32            unknown => Scheme::Ext(unknown.into()),
33        }
34    }
35}
36
37impl Scheme {
38    /// Return ourselves parseable name.
39    pub fn as_str(&self) -> &str {
40        use Scheme::*;
41        match self {
42            File => "file",
43            Git => "git",
44            Ssh => "ssh",
45            Http => "http",
46            Https => "https",
47            Ext(name) => name.as_str(),
48        }
49    }
50}
51
52impl std::fmt::Display for Scheme {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        f.write_str(self.as_str())
55    }
56}