upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/git/nostr_url.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs
index 6fcc11d..42b0ac9 100644
--- a/src/lib/git/nostr_url.rs
+++ b/src/lib/git/nostr_url.rs
@@ -1,7 +1,7 @@
1use core::fmt; 1use core::fmt;
2use std::{collections::HashSet, str::FromStr}; 2use std::{collections::HashSet, str::FromStr};
3 3
4use anyhow::{anyhow, bail, Context, Result}; 4use anyhow::{anyhow, bail, Context, Error, Result};
5use nostr::nips::nip01::Coordinate; 5use nostr::nips::nip01::Coordinate;
6use nostr_sdk::{PublicKey, Url}; 6use nostr_sdk::{PublicKey, Url};
7 7
@@ -34,6 +34,25 @@ impl fmt::Display for ServerProtocol {
34 } 34 }
35} 35}
36 36
37impl FromStr for ServerProtocol {
38 type Err = Error;
39
40 // Method to convert a string to a ServerProtocol variant
41 fn from_str(s: &str) -> Result<ServerProtocol> {
42 match s {
43 "http" => Ok(ServerProtocol::Http),
44 "https" => Ok(ServerProtocol::Https),
45 "ftp" => Ok(ServerProtocol::Ftp),
46 "ssh" => Ok(ServerProtocol::Ssh),
47 "git" => Ok(ServerProtocol::Git),
48 "filesystem" => Ok(ServerProtocol::Filesystem),
49 "http (unauthenticated)" => Ok(ServerProtocol::UnauthHttp),
50 "https (unauthenticated)" => Ok(ServerProtocol::UnauthHttps),
51 _ => bail!("not listed as a server protocol"),
52 }
53 }
54}
55
37#[derive(Debug, PartialEq)] 56#[derive(Debug, PartialEq)]
38pub struct NostrUrlDecoded { 57pub struct NostrUrlDecoded {
39 pub original_string: String, 58 pub original_string: String,