Skip to content

Commit eee955e

Browse files
committed
use async closure
1 parent b960301 commit eee955e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

async-openai-wasm/src/client.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<C: Config> Client<C> {
166166
where
167167
O: DeserializeOwned,
168168
{
169-
let request_maker = || async {
169+
let request_maker = async || {
170170
Ok(self
171171
.http_client
172172
.get(self.config.url(path))
@@ -184,7 +184,7 @@ impl<C: Config> Client<C> {
184184
O: DeserializeOwned,
185185
Q: Serialize + ?Sized,
186186
{
187-
let request_maker = || async {
187+
let request_maker = async || {
188188
Ok(self
189189
.http_client
190190
.get(self.config.url(path))
@@ -202,7 +202,7 @@ impl<C: Config> Client<C> {
202202
where
203203
O: DeserializeOwned,
204204
{
205-
let request_maker = || async {
205+
let request_maker = async || {
206206
Ok(self
207207
.http_client
208208
.delete(self.config.url(path))
@@ -216,7 +216,7 @@ impl<C: Config> Client<C> {
216216

217217
/// Make a GET request to {path} and return the response body
218218
pub(crate) async fn get_raw(&self, path: &str) -> Result<Bytes, OpenAIError> {
219-
let request_maker = || async {
219+
let request_maker = async || {
220220
Ok(self
221221
.http_client
222222
.get(self.config.url(path))
@@ -233,7 +233,7 @@ impl<C: Config> Client<C> {
233233
where
234234
I: Serialize,
235235
{
236-
let request_maker = || async {
236+
let request_maker = async || {
237237
Ok(self
238238
.http_client
239239
.post(self.config.url(path))
@@ -252,7 +252,7 @@ impl<C: Config> Client<C> {
252252
I: Serialize,
253253
O: DeserializeOwned,
254254
{
255-
let request_maker = || async {
255+
let request_maker = async || {
256256
Ok(self
257257
.http_client
258258
.post(self.config.url(path))
@@ -271,7 +271,7 @@ impl<C: Config> Client<C> {
271271
Form: AsyncTryFrom<F, Error = OpenAIError>,
272272
F: Clone,
273273
{
274-
let request_maker = || async {
274+
let request_maker = async || {
275275
Ok(self
276276
.http_client
277277
.post(self.config.url(path))
@@ -291,7 +291,7 @@ impl<C: Config> Client<C> {
291291
Form: AsyncTryFrom<F, Error = OpenAIError>,
292292
F: Clone,
293293
{
294-
let request_maker = || async {
294+
let request_maker = async || {
295295
Ok(self
296296
.http_client
297297
.post(self.config.url(path))
@@ -309,11 +309,10 @@ impl<C: Config> Client<C> {
309309
/// request_maker serves one purpose: to be able to create request again
310310
/// to retry API call after getting rate limited. request_maker is async because
311311
/// reqwest::multipart::Form is created by async calls to read files for uploads.
312-
async fn execute_raw<M, Fut>(&self, request_maker: M) -> Result<Bytes, OpenAIError>
313-
where
314-
M: Fn() -> Fut,
315-
Fut: future::Future<Output = Result<reqwest::Request, OpenAIError>>,
316-
{
312+
async fn execute_raw(
313+
&self,
314+
request_maker: impl AsyncFn() -> Result<reqwest::Request, OpenAIError>,
315+
) -> Result<Bytes, OpenAIError> {
317316
let client = self.http_client.clone();
318317

319318
let request = request_maker().await?;
@@ -351,11 +350,12 @@ impl<C: Config> Client<C> {
351350
/// request_maker serves one purpose: to be able to create request again
352351
/// to retry API call after getting rate limited. request_maker is async because
353352
/// reqwest::multipart::Form is created by async calls to read files for uploads.
354-
async fn execute<O, M, Fut>(&self, request_maker: M) -> Result<O, OpenAIError>
353+
async fn execute<O>(
354+
&self,
355+
request_maker: impl AsyncFn() -> Result<reqwest::Request, OpenAIError>,
356+
) -> Result<O, OpenAIError>
355357
where
356358
O: DeserializeOwned,
357-
M: Fn() -> Fut,
358-
Fut: core::future::Future<Output = Result<reqwest::Request, OpenAIError>>,
359359
{
360360
let bytes = self.execute_raw(request_maker).await?;
361361

0 commit comments

Comments
 (0)