diff options
Diffstat (limited to 'src/lib/mod.rs')
| -rw-r--r-- | src/lib/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 2072a80..7c7bd6a 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs | |||
| @@ -8,9 +8,30 @@ pub mod repo_state; | |||
| 8 | 8 | ||
| 9 | use anyhow::{Result, anyhow}; | 9 | use anyhow::{Result, anyhow}; |
| 10 | use directories::ProjectDirs; | 10 | use directories::ProjectDirs; |
| 11 | use nostr_sdk::Url; | ||
| 11 | 12 | ||
| 12 | pub fn get_dirs() -> Result<ProjectDirs> { | 13 | pub fn get_dirs() -> Result<ProjectDirs> { |
| 13 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( | 14 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( |
| 14 | "should find operating system home directories with rust-directories crate" | 15 | "should find operating system home directories with rust-directories crate" |
| 15 | )) | 16 | )) |
| 16 | } | 17 | } |
| 18 | |||
| 19 | pub trait UrlWithoutSlash { | ||
| 20 | fn as_str_without_trailing_slash(&self) -> &str; | ||
| 21 | fn to_string_without_trailing_slash(&self) -> String; | ||
| 22 | } | ||
| 23 | |||
| 24 | impl UrlWithoutSlash for Url { | ||
| 25 | fn as_str_without_trailing_slash(&self) -> &str { | ||
| 26 | let url_str = self.as_str(); | ||
| 27 | if let Some(without) = url_str.strip_suffix('/') { | ||
| 28 | without | ||
| 29 | } else { | ||
| 30 | url_str | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | fn to_string_without_trailing_slash(&self) -> String { | ||
| 35 | self.as_str_without_trailing_slash().to_string() | ||
| 36 | } | ||
| 37 | } | ||