From 90c53e2dc859b47615ebaa08199b7460615ce3e4 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 4 Sep 2024 14:40:27 +0100 Subject: refactor: use FromStr trait for NostrUrlDecoded as it should have been used in the first place --- src/bin/git_remote_nostr/list.rs | 0 src/bin/git_remote_nostr/main.rs | 1 + src/lib/git/nostr_url.rs | 8 ++++++-- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/bin/git_remote_nostr/list.rs (limited to 'src') diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index 3e08efe..8d67552 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -10,6 +10,7 @@ use std::{ env, io::{self, Stdin}, path::{Path, PathBuf}, + str::FromStr, }; use anyhow::{anyhow, bail, Context, Result}; diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index ce3e973..d1fee2e 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -21,8 +21,10 @@ pub struct NostrUrlDecoded { static INCORRECT_NOSTR_URL_FORMAT_ERROR: &str = "incorrect nostr git url format. try nostr://naddr123 or nostr://npub123/my-repo or nostr://ssh/npub123/relay.damus.io/my-repo"; -impl NostrUrlDecoded { - pub fn from_str(url: &str) -> Result { +impl std::str::FromStr for NostrUrlDecoded { + type Err = anyhow::Error; + + fn from_str(url: &str) -> Result { let mut coordinates = HashSet::new(); let mut protocol = None; let mut user = None; @@ -257,6 +259,8 @@ mod tests { } mod nostr_git_url_paramemters_from_str { + use std::str::FromStr; + use super::*; fn get_model_coordinate(relays: bool) -> Coordinate { -- cgit v1.2.3