upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mod.rs')
-rw-r--r--src/lib/mod.rs21
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
9use anyhow::{Result, anyhow}; 9use anyhow::{Result, anyhow};
10use directories::ProjectDirs; 10use directories::ProjectDirs;
11use nostr_sdk::Url;
11 12
12pub fn get_dirs() -> Result<ProjectDirs> { 13pub 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
19pub trait UrlWithoutSlash {
20 fn as_str_without_trailing_slash(&self) -> &str;
21 fn to_string_without_trailing_slash(&self) -> String;
22}
23
24impl 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}