summaryrefslogtreecommitdiffstats
path: root/vendor/gix-url/src/scheme.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix-url/src/scheme.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-url/src/scheme.rs')
-rw-r--r--vendor/gix-url/src/scheme.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/gix-url/src/scheme.rs b/vendor/gix-url/src/scheme.rs
new file mode 100644
index 000000000..5f491596a
--- /dev/null
+++ b/vendor/gix-url/src/scheme.rs
@@ -0,0 +1,56 @@
+/// A scheme or protocol for use in a [`Url`][crate::Url].
+///
+/// It defines how to talk to a given repository.
+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
+#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[allow(missing_docs)]
+pub enum Scheme {
+ /// A local resource that is accessible on the current host.
+ File,
+ /// A git daemon, like `File` over TCP/IP.
+ Git,
+ /// Launch `git-upload-pack` through an `ssh` tunnel.
+ Ssh,
+ /// Use the HTTP protocol to talk to git servers.
+ Http,
+ /// Use the HTTPS protocol to talk to git servers.
+ Https,
+ /// Any other protocol or transport that isn't known at compile time.
+ ///
+ /// It's used to support plug-in transports.
+ Ext(String),
+}
+
+impl<'a> From<&'a str> for Scheme {
+ fn from(value: &'a str) -> Self {
+ match value {
+ "ssh" => Scheme::Ssh,
+ "file" => Scheme::File,
+ "git" => Scheme::Git,
+ "http" => Scheme::Http,
+ "https" => Scheme::Https,
+ unknown => Scheme::Ext(unknown.into()),
+ }
+ }
+}
+
+impl Scheme {
+ /// Return ourselves parseable name.
+ pub fn as_str(&self) -> &str {
+ use Scheme::*;
+ match self {
+ File => "file",
+ Git => "git",
+ Ssh => "ssh",
+ Http => "http",
+ Https => "https",
+ Ext(name) => name.as_str(),
+ }
+ }
+}
+
+impl std::fmt::Display for Scheme {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(self.as_str())
+ }
+}