James Farrell | 917a5f3 | 2023-08-16 18:19:42 +0000 | [diff] [blame] | 1 | #![allow(dead_code)] |
| 2 | |
| 3 | use maybe_async::maybe_async; |
| 4 | |
| 5 | #[maybe_async(Send)] |
| 6 | trait Trait { |
| 7 | fn sync_fn() {} |
| 8 | |
| 9 | async fn declare_async(&self); |
| 10 | |
| 11 | async fn async_fn(&self) { |
| 12 | self.declare_async().await |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | #[maybe_async(?Send)] |
| 17 | pub trait PubTrait { |
| 18 | fn sync_fn() {} |
| 19 | |
| 20 | async fn declare_async(&self); |
| 21 | |
| 22 | async fn async_fn(&self) { |
| 23 | self.declare_async().await |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | #[maybe_async] |
| 28 | pub(crate) trait PubCrateTrait { |
| 29 | fn sync_fn() {} |
| 30 | |
| 31 | async fn declare_async(&self); |
| 32 | |
| 33 | async fn async_fn(&self) { |
| 34 | self.declare_async().await |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #[maybe_async] |
| 39 | async fn async_fn() {} |
| 40 | |
| 41 | #[maybe_async] |
| 42 | pub async fn pub_async_fn() {} |
| 43 | |
| 44 | #[maybe_async] |
| 45 | pub(crate) async fn pub_crate_async_fn() {} |
| 46 | |
| 47 | #[maybe_async] |
| 48 | unsafe fn unsafe_fn() {} |
| 49 | |
| 50 | struct Struct; |
| 51 | |
| 52 | #[maybe_async] |
| 53 | impl Trait for Struct { |
| 54 | fn sync_fn() {} |
| 55 | |
| 56 | async fn declare_async(&self) {} |
| 57 | |
| 58 | async fn async_fn(&self) { |
| 59 | async { self.declare_async().await }.await |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | #[cfg(feature = "is_sync")] |
| 64 | fn main() -> std::result::Result<(), ()> { |
| 65 | let s = Struct; |
| 66 | s.declare_async(); |
| 67 | s.async_fn(); |
| 68 | async_fn(); |
| 69 | pub_async_fn(); |
| 70 | Ok(()) |
| 71 | } |
| 72 | |
| 73 | #[cfg(not(feature = "is_sync"))] |
| 74 | #[async_std::main] |
| 75 | async fn main() { |
| 76 | let s = Struct; |
| 77 | s.declare_async().await; |
| 78 | s.async_fn().await; |
| 79 | async_fn().await; |
| 80 | pub_async_fn().await; |
| 81 | } |