-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move all public bounds into traits except spawn
- Loading branch information
Showing
7 changed files
with
112 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! Provides an easy way for calling functions to reuse bounds of public | ||
//! functions except [spawn][crate::spawn] for which I couldn't foresee the use | ||
//! case. If you have a use case reach out, don't mind adding it if it adds | ||
//! value. All these traits come with automatic impls so they are automatically | ||
//! implemented for any function that meets the bounds functions that are | ||
//! conditionally compiled by target | ||
// Unable to actually include this text for docs.rs because when this module is | ||
|
||
// public the traits it includes do not show up as Traits at the top level of | ||
// the crate. | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
mod native; | ||
#[cfg(target_arch = "wasm32")] | ||
mod wasm; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub use native::*; | ||
#[cfg(target_arch = "wasm32")] | ||
pub use wasm::*; | ||
|
||
/// 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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::future::Future; | ||
|
||
/// dox | ||
pub trait ResponseHandler<Fut, O>: | ||
'static + FnOnce(reqwest::Result<reqwest::Response>) -> Fut | ||
where | ||
Fut: BoundedFuture<O>, | ||
{ | ||
} | ||
impl<T, Fut, O> ResponseHandler<Fut, O> for T | ||
where | ||
T: 'static + FnOnce(reqwest::Result<reqwest::Response>) -> Fut, | ||
Fut: BoundedFuture<O>, | ||
{ | ||
} | ||
|
||
/// dox | ||
pub trait BoundedFuture<O>: Future<Output = O> {} | ||
impl<T, O> BoundedFuture<O> for T where T: Future<Output = O> {} | ||
|
||
/// dox | ||
pub trait DoneHandler<O>: 'static + FnOnce(reqwest::Result<reqwest::Response>) -> O | ||
where | ||
O: BoundedFuture<()>, | ||
{ | ||
} | ||
impl<T, O: BoundedFuture<()>> DoneHandler<O> for T where | ||
T: 'static + FnOnce(reqwest::Result<reqwest::Response>) -> O | ||
{ | ||
} |