use std::{future::Future, str::FromStr};
use serde::de::DeserializeOwned;
use crate::errors::OapiError;
use crate::rest::{RequestOptions, post::apply_options};
pub trait Delete {
fn build_url(&self, base_url: &str) -> Result<String, OapiError>;
}
pub trait DeleteNoStream: Delete + Send + Sync {
type Response: DeserializeOwned + FromStr<Err = OapiError> + Send + Sync;
fn get_response_string(
&self,
client: &reqwest::Client,
base_url: &str,
options: &RequestOptions,
) -> impl Future<Output = Result<String, OapiError>> + Send + Sync {
async move {
let url = self.build_url(base_url)?;
let response = apply_options(
client.delete(url).header("Accept", "application/json"),
options,
)
.send()
.await?;
crate::rest::response_text_checked(response).await
}
}
fn get_response(
&self,
client: &reqwest::Client,
base_url: &str,
options: &RequestOptions,
) -> impl Future<Output = Result<Self::Response, OapiError>> + Send + Sync {
async move {
let text = self.get_response_string(client, base_url, options).await?;
let result = Self::Response::from_str(&text)?;
Ok(result)
}
}
}