openai_interface/rest/
delete.rs1use std::{future::Future, str::FromStr};
4
5use serde::de::DeserializeOwned;
6
7use crate::errors::OapiError;
8use crate::rest::{RequestOptions, post::apply_options};
9
10pub trait Delete {
11 fn build_url(&self, base_url: &str) -> Result<String, OapiError>;
16}
17
18pub trait DeleteNoStream: Delete + Send + Sync {
19 type Response: DeserializeOwned + FromStr<Err = OapiError> + Send + Sync;
20
21 fn get_response_string(
26 &self,
27 client: &reqwest::Client,
28 base_url: &str,
29 options: &RequestOptions,
30 ) -> impl Future<Output = Result<String, OapiError>> + Send + Sync {
31 async move {
32 let url = self.build_url(base_url)?;
33
34 let response = apply_options(
35 client.delete(url).header("Accept", "application/json"),
36 options,
37 )
38 .send()
39 .await?;
40
41 crate::rest::response_text_checked(response).await
42 }
43 }
44
45 fn get_response(
47 &self,
48 client: &reqwest::Client,
49 base_url: &str,
50 options: &RequestOptions,
51 ) -> impl Future<Output = Result<Self::Response, OapiError>> + Send + Sync {
52 async move {
53 let text = self.get_response_string(client, base_url, options).await?;
54 let result = Self::Response::from_str(&text)?;
55 Ok(result)
56 }
57 }
58}