diff --git a/src/macros.rs b/src/macros.rs index 85b6c5e..3d9d54a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -480,12 +480,12 @@ macro_rules! paged_routes_with_id { "client.", stringify!($name), "(\"some-id\");\n", "```" ), - pub async fn $name(&self, id: &str) -> Result> { + pub async fn $name(&self, id: impl AsRef) -> Result> { use log::{debug, as_debug}; use uuid::Uuid; let call_id = Uuid::new_v4(); - let url = self.route(&format!(concat!("/api/v1/", $url), id)); + let url = self.route(&format!(concat!("/api/v1/", $url), id.as_ref())); debug!(url = url, method = stringify!($method), call_id = as_debug!(call_id); "making API request"); let response = self.authenticated(self.client.$method(&url)).header("Accept", "application/json").send().await?; diff --git a/src/mastodon.rs b/src/mastodon.rs index aef3bb7..79c7580 100644 --- a/src/mastodon.rs +++ b/src/mastodon.rs @@ -153,8 +153,8 @@ impl Mastodon { Mastodon(Arc::new(MastodonClient { client, data })) } - fn route(&self, url: &str) -> String { - format!("{}{}", self.data.base, url) + fn route(&self, url: impl AsRef) -> String { + format!("{}{}", self.data.base, url.as_ref()) } /// POST /api/v1/filters @@ -171,7 +171,7 @@ impl Mastodon { /// PUT /api/v1/filters/:id pub async fn update_filter(&self, id: &str, request: &mut AddFilterRequest) -> Result { - let url = self.route(&format!("/api/v1/filters/{}", id)); + let url = self.route(format!("/api/v1/filters/{}", id)); let response = self.client.put(&url).json(&request).send().await?; read_response(response).await @@ -207,9 +207,9 @@ impl Mastodon { pub async fn get_tagged_timeline(&self, hashtag: String, local: bool) -> Result> { let base = "/api/v1/timelines/tag/"; let url = if local { - self.route(&format!("{}{}?local=1", base, hashtag)) + self.route(format!("{}{}?local=1", base, hashtag)) } else { - self.route(&format!("{}{}", base, hashtag)) + self.route(format!("{}{}", base, hashtag)) }; self.get(url).await