reqwest_cross/traits/
native.rs

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
use std::future::Future;

/// An async func that accepts a [reqwest::Response]
/// and returns a generic value
pub trait ResponseHandler<Fut, O>:
    Send + 'static + FnOnce(reqwest::Result<reqwest::Response>) -> Fut
where
    Fut: BoundedFuture<O>,
{
}
impl<T, Fut, O> ResponseHandler<Fut, O> for T
where
    T: Send + 'static + FnOnce(reqwest::Result<reqwest::Response>) -> Fut,
    Fut: BoundedFuture<O>,
{
}

/// A function that receives the [reqwest::Response]
/// and returns it to the application via some means (See examples for way it
/// can be done)
pub trait DoneHandler<O>: 'static + Send + FnOnce(reqwest::Result<reqwest::Response>) -> O
where
    O: BoundedFuture<()>,
{
}
impl<T, O: BoundedFuture<()>> DoneHandler<O> for T where
    T: 'static + Send + FnOnce(reqwest::Result<reqwest::Response>) -> O
{
}

/// A future with the required bounds for the platform
pub trait BoundedFuture<O>: Future<Output = O> + Send {}
impl<T, O> BoundedFuture<O> for T where T: Future<Output = O> + Send {}

/// A function able to be used as a Call Back to notify the UI that the request
/// is ready
pub trait UiCallBack: 'static + Send + FnOnce() {}
impl<T> UiCallBack for T where T: 'static + Send + FnOnce() {}

/// Allowed return types
pub trait ValidReturn: Send + 'static {}
impl<T: Send + 'static> ValidReturn for T {}