reqwest_cross/traits/
native.rs

1use std::future::Future;
2
3/// An async func that accepts a [reqwest::Response]
4/// and returns a generic value
5pub trait ResponseHandler<Fut, O>:
6    Send + 'static + FnOnce(reqwest::Result<reqwest::Response>) -> Fut
7where
8    Fut: BoundedFuture<O>,
9{
10}
11impl<T, Fut, O> ResponseHandler<Fut, O> for T
12where
13    T: Send + 'static + FnOnce(reqwest::Result<reqwest::Response>) -> Fut,
14    Fut: BoundedFuture<O>,
15{
16}
17
18/// A function that receives the [reqwest::Response]
19/// and returns it to the application via some means (See examples for way it
20/// can be done)
21pub trait DoneHandler<O>: 'static + Send + FnOnce(reqwest::Result<reqwest::Response>) -> O
22where
23    O: BoundedFuture<()>,
24{
25}
26impl<T, O: BoundedFuture<()>> DoneHandler<O> for T where
27    T: 'static + Send + FnOnce(reqwest::Result<reqwest::Response>) -> O
28{
29}
30
31/// A future with the required bounds for the platform
32pub trait BoundedFuture<O>: Future<Output = O> + Send {}
33impl<T, O> BoundedFuture<O> for T where T: Future<Output = O> + Send {}
34
35/// A function able to be used as a Call Back to notify the UI that the request
36/// is ready
37pub trait UiCallBack: 'static + Send + FnOnce() {}
38impl<T> UiCallBack for T where T: 'static + Send + FnOnce() {}
39
40/// Allowed return types
41pub trait ValidReturn: Send + 'static {}
42impl<T: Send + 'static> ValidReturn for T {}