-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for choosing between async-std and Tokio #29
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::File; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::File; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use futures::io::AsyncRead; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::io::AsyncRead; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use futures::io::AsyncReadExt; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::io::AsyncReadExt; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use futures::io::AsyncBufReadExt; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::io::AsyncBufReadExt; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use futures::io::AsyncWrite; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::io::AsyncWrite; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use futures::io::AsyncWriteExt; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::io::AsyncWriteExt; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::read; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::read; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::copy; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::copy; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::metadata; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::metadata; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::remove_file; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::remove_file; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::create_dir_all; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::create_dir_all; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::remove_dir_all; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::remove_dir_all; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::DirBuilder; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::DirBuilder; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::fs::OpenOptions; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::fs::OpenOptions; | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::io::BufReader; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::io::BufReader; | ||
|
||
#[cfg(feature = "async-std")] | ||
#[inline] | ||
pub fn lines_to_stream<R>(lines: futures::io::Lines<R>) -> futures::io::Lines<R> { | ||
lines | ||
} | ||
#[cfg(feature = "tokio")] | ||
#[inline] | ||
pub fn lines_to_stream<R>(lines: tokio::io::Lines<R>) -> tokio_stream::wrappers::LinesStream<R> { | ||
tokio_stream::wrappers::LinesStream::new(lines) | ||
} | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::task::spawn_blocking; | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::task::spawn_blocking; | ||
|
||
#[cfg(all(test, feature = "async-std"))] | ||
pub use async_std::task::block_on; | ||
#[cfg(all(test, feature = "tokio"))] | ||
#[inline] | ||
pub fn block_on<F, T>(future: F) -> T | ||
where | ||
F: std::future::Future<Output = T>, | ||
{ | ||
tokio::runtime::Runtime::new().unwrap().block_on(future) | ||
} | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::task::JoinHandle; | ||
#[cfg(feature = "async-std")] | ||
#[inline] | ||
pub async fn unwrap_joinhandle<R>(handle: async_std::task::JoinHandle<R>) -> R { | ||
handle.await | ||
} | ||
#[cfg(feature = "async-std")] | ||
#[inline] | ||
pub fn unwrap_joinhandle_value<T>(value: T) -> T { | ||
value | ||
} | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::task::JoinHandle; | ||
#[cfg(feature = "tokio")] | ||
#[inline] | ||
pub async fn unwrap_joinhandle<R>(handle: tokio::task::JoinHandle<R>) -> R { | ||
handle.await.unwrap() | ||
} | ||
#[cfg(feature = "tokio")] | ||
#[inline] | ||
pub fn unwrap_joinhandle_value<T>(value: Result<T, tokio::task::JoinError>) -> T { | ||
value.unwrap() | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combined with
it doesn't really change anything for your existing users unless they've put
default-features = false
on the dependency already, which would be a really odd thing to do on a crate which had no features.