1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use async_trait::async_trait;
use reqwest::RequestBuilder;
use serde::de::DeserializeOwned;
use crate::{Auth0Client, Auth0Result};
#[async_trait]
pub trait Auth0Request {
async fn send<T>(&self) -> Auth0Result<T>
where
T: DeserializeOwned + Send + Sync;
}
#[async_trait]
pub trait Auth0RequestSimple {
async fn send_to<T>(&self, client: &Auth0Client) -> Auth0Result<T>
where
T: DeserializeOwned + Send + Sync;
}
pub trait Auth0RequestBuilder {
fn build(&self, client: &Auth0Client) -> RequestBuilder;
}
#[async_trait]
impl<A: Auth0RequestBuilder + Send + Sync> Auth0RequestSimple for A {
async fn send_to<T>(&self, client: &Auth0Client) -> Auth0Result<T>
where
T: DeserializeOwned + Send + Sync,
{
client.send(self.build(&client)).await
}
}
#[async_trait]
impl<A: Auth0RequestBuilder + AsRef<Auth0Client> + Sync + Send> Auth0Request for A {
async fn send<T>(&self) -> Auth0Result<T>
where
T: DeserializeOwned + Send + Sync,
{
let client = self.as_ref();
let req = self.build(&client);
client.send(req).await
}
}