From f8a748ec078f08427b79b5ff32a1e28625de572b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 4 Jun 2025 22:01:17 +0000 Subject: [PATCH] sharry::api::Uri handling --- src/sharry/alias.rs | 11 ++++------- src/sharry/api.rs | 15 ++++++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/sharry/alias.rs b/src/sharry/alias.rs index bd8a8d0..7dcb0a1 100644 --- a/src/sharry/alias.rs +++ b/src/sharry/alias.rs @@ -8,7 +8,7 @@ use super::api::Uri; #[derive(Serialize, Deserialize, Debug, Hash)] pub struct Alias { - pub(super) api_uri: String, + pub(super) uri: Uri, pub(super) id: String, } @@ -23,15 +23,12 @@ impl SharryAlias for RequestBuilder { } impl Alias { - pub fn new(api_uri: Uri, id: impl Into) -> Self { - Self { - api_uri: api_uri.into(), - id: id.into(), - } + pub fn new(uri: Uri, id: impl Into) -> Self { + Self { uri, id: id.into() } } pub(super) fn get_endpoint(&self, endpoint: impl Display + Debug) -> String { - let uri = format!("{}/{}", self.api_uri, endpoint); + let uri = format!("{}/{}", self.uri.to_string(), endpoint); debug!("endpoint uri: {uri:?}"); uri diff --git a/src/sharry/api.rs b/src/sharry/api.rs index af280cb..8d18ecf 100644 --- a/src/sharry/api.rs +++ b/src/sharry/api.rs @@ -1,5 +1,8 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; +#[derive(Serialize, Deserialize, Debug, Hash)] pub struct Uri { protocol: String, base_url: String, @@ -14,15 +17,9 @@ impl Uri { } } -impl From<&str> for Uri { - fn from(value: &str) -> Self { - Self::with_protocol("https", value) - } -} - -impl From for String { - fn from(val: Uri) -> Self { - format!("{}://{}/api/v2", val.protocol, val.base_url) +impl Display for Uri { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}://{}/api/v2", self.protocol, self.base_url) } }