Hi all
I have the following below
/// Slack WEB API Client.
#[cfg_attr(test, automock)]
#[async_trait]
pub trait SlackWebAPIClient: Sync + Send {
async fn post_json(&self, url: &str, body: &str, token: &str) -> Result<String, Error>;
async fn post(&self, url: &str, token: &str) -> Result<String, Error>;
async fn get(&self, url: &str, query: &str, token: &str) -> Result<String, Error>;
}
/// HTTP Client(surf::Client).
pub type Client = surf::Client;
#[async_trait]
impl SlackWebAPIClient for Client {
/// Send a post request including the body to the slack web api.
async fn post_json(&self, url: &str, body: &str, token: &str) -> Result<String, Error> {
let check_url = url::Url::parse(url)?;
Ok(self
.post(check_url)
.header("Authorization", format!("Bearer {}", token))
.header("Content-type", "application/json; charset=utf-8")
.body(body)
.await?
.body_string()
.await?)
}
/// Send a post request to the slack web api.
async fn post(&self, url: &str, token: &str) -> Result<String, Error> {
let check_url = url::Url::parse(url)?;
Ok(self
.post(check_url)
.header("Authorization", format!("Bearer {}", token))
.await?
.body_string()
.await?)
}
/// Send a get request to the slack web api.
async fn get(&self, url: &str, query: &str, token: &str) -> Result<String, Error> {
let check_url = url::Url::parse(url)?;
Ok(self
.get(check_url)
.header("Authorization", format!("Bearer {}", token))
.query(&query)?
.await?
.body_string()
.await?)
}
}
where I like to change the definition of the query parameter to exactly like in the surf library
pub fn query(mut self, query: &impl Serialize) -> std::result::Result<Self, Error> {
self.req.as_mut().unwrap().set_query(query)?;
Ok(self)
}
But it looks like I cant add a trait within a trait
hope to get some help on this
thanks