summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorD. Scott Boggs <scott@tams.tech>2023-01-09 08:04:07 -0500
committerScott Boggs <dscottboggs@gmail.com>2023-01-09 09:03:21 -0500
commit6e044c3f3505f57df1c4a295df6939eac43371b3 (patch)
tree8f31f8262297c19ac52aa0279b430caa9533639a
parent06caec85b37e7fd6842610af92076873768f7552 (diff)
Use `impl AsRef<str>` instead of `&str` to work with new ID types
-rw-r--r--src/macros.rs4
-rw-r--r--src/mastodon.rs10
2 files changed, 7 insertions, 7 deletions
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<Page<$ret>> {
+ pub async fn $name(&self, id: impl AsRef<str>) -> Result<Page<$ret>> {
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<str>) -> 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<Filter> {
- 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<Vec<Status>> {
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