Use `impl AsRef<str>` instead of `&str` to work with new ID types
This commit is contained in:
parent
06caec85b3
commit
6e044c3f35
|
@ -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?;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue