|
| 1 | +#[cfg(not(any( |
| 2 | + feature = "runtime-actix", |
| 3 | + feature = "runtime-async-std", |
| 4 | + feature = "runtime-tokio", |
| 5 | +)))] |
| 6 | +compile_error!( |
| 7 | + "one of 'runtime-actix', 'runtime-async-std' or 'runtime-tokio' features must be enabled" |
| 8 | +); |
| 9 | + |
| 10 | +#[cfg(any( |
| 11 | + all(feature = "runtime-actix", feature = "runtime-async-std"), |
| 12 | + all(feature = "runtime-actix", feature = "runtime-tokio"), |
| 13 | + all(feature = "runtime-async-std", feature = "runtime-tokio"), |
| 14 | +))] |
| 15 | +compile_error!( |
| 16 | + "only one of 'runtime-actix', 'runtime-async-std' or 'runtime-tokio' features can be enabled" |
| 17 | +); |
| 18 | + |
| 19 | +pub use native_tls; |
| 20 | + |
| 21 | +// |
| 22 | +// Actix *OR* Tokio |
| 23 | +// |
| 24 | + |
| 25 | +#[cfg(all( |
| 26 | + not(feature = "runtime-async-std"), |
| 27 | + any(feature = "runtime-tokio", feature = "runtime-actix"), |
| 28 | +))] |
| 29 | +pub use tokio::{ |
| 30 | + self, fs, io::AsyncRead, io::AsyncReadExt, io::AsyncWrite, io::AsyncWriteExt, net::TcpStream, |
| 31 | + task::yield_now, |
| 32 | +}; |
| 33 | + |
| 34 | +#[cfg(all( |
| 35 | + unix, |
| 36 | + not(feature = "runtime-async-std"), |
| 37 | + any(feature = "runtime-tokio", feature = "runtime-actix"), |
| 38 | +))] |
| 39 | +pub use tokio::net::UnixStream; |
| 40 | + |
| 41 | +// |
| 42 | +// tokio |
| 43 | +// |
| 44 | + |
| 45 | +#[cfg(all( |
| 46 | + feature = "runtime-tokio", |
| 47 | + not(any(feature = "runtime-actix", feature = "runtime-async-std",)) |
| 48 | +))] |
| 49 | +#[macro_export] |
| 50 | +macro_rules! blocking { |
| 51 | + ($($expr:tt)*) => { |
| 52 | + $crate::tokio::task::block_in_place(move || { $($expr)* }) |
| 53 | + }; |
| 54 | +} |
| 55 | + |
| 56 | +#[cfg(all(feature = "tokio-native-tls", not(feature = "async-native-tls")))] |
| 57 | +pub use tokio_native_tls::{TlsConnector, TlsStream}; |
| 58 | + |
| 59 | +#[cfg(all(feature = "tokio-native-tls", not(feature = "async-native-tls")))] |
| 60 | +pub use native_tls::Error as TlsError; |
| 61 | + |
| 62 | +// |
| 63 | +// actix |
| 64 | +// |
| 65 | + |
| 66 | +#[cfg(feature = "runtime-actix")] |
| 67 | +pub use {actix_rt, actix_threadpool}; |
| 68 | + |
| 69 | +#[cfg(all( |
| 70 | + feature = "runtime-actix", |
| 71 | + not(any(feature = "runtime-tokio", feature = "runtime-async-std",)) |
| 72 | +))] |
| 73 | +#[macro_export] |
| 74 | +macro_rules! blocking { |
| 75 | + ($($expr:tt)*) => { |
| 76 | + $crate::actix_threadpool::run(move || { $($expr)* }).await.map_err(|err| match err { |
| 77 | + $crate::actix_threadpool::BlockingError::Error(e) => e, |
| 78 | + $crate::actix_threadpool::BlockingError::Canceled => panic!("{}", err) |
| 79 | + }) |
| 80 | + }; |
| 81 | +} |
| 82 | + |
| 83 | +// |
| 84 | +// async-std |
| 85 | +// |
| 86 | + |
| 87 | +#[cfg(all( |
| 88 | + feature = "runtime-async-std", |
| 89 | + not(any(feature = "runtime-actix", feature = "runtime-tokio",)) |
| 90 | +))] |
| 91 | +pub use async_std::{ |
| 92 | + self, fs, io::prelude::ReadExt as AsyncReadExt, io::prelude::WriteExt as AsyncWriteExt, |
| 93 | + io::Read as AsyncRead, io::Write as AsyncWrite, net::TcpStream, task::spawn, task::yield_now, |
| 94 | +}; |
| 95 | + |
| 96 | +#[cfg(all( |
| 97 | + feature = "runtime-async-std", |
| 98 | + not(any(feature = "runtime-actix", feature = "runtime-tokio",)) |
| 99 | +))] |
| 100 | +#[macro_export] |
| 101 | +macro_rules! blocking { |
| 102 | + ($($expr:tt)*) => { |
| 103 | + $crate::async_std::task::spawn_blocking(move || { $($expr)* }).await |
| 104 | + }; |
| 105 | +} |
| 106 | + |
| 107 | +#[cfg(all( |
| 108 | + unix, |
| 109 | + feature = "runtime-async-std", |
| 110 | + not(any(feature = "runtime-actix", feature = "runtime-tokio",)) |
| 111 | +))] |
| 112 | +pub use async_std::os::unix::net::UnixStream; |
| 113 | + |
| 114 | +#[cfg(all(feature = "async-native-tls", not(feature = "tokio-native-tls")))] |
| 115 | +pub use async_native_tls::{Error as TlsError, TlsConnector, TlsStream}; |
0 commit comments