1 #![allow(dead_code)]
2 
3 #[maybe_async::maybe_async]
4 trait Trait {
sync_fn()5     fn sync_fn() {}
6 
declare_async(&self)7     async fn declare_async(&self);
8 
async_fn(&self)9     async fn async_fn(&self) {
10         self.declare_async().await
11     }
12 }
13 
14 #[maybe_async::maybe_async(?Send)]
15 trait NotSendTrait {
declare_async_not_send(&self)16     async fn declare_async_not_send(&self);
17 
async_fn_not_send(&self)18     async fn async_fn_not_send(&self) {
19         self.declare_async_not_send().await
20     }
21 }
22 
23 #[maybe_async::maybe_async]
24 pub trait PubTrait {
sync_fn()25     fn sync_fn() {}
26 
declare_async(&self)27     async fn declare_async(&self);
28 
async_fn(&self)29     async fn async_fn(&self) {
30         self.declare_async().await
31     }
32 }
33 
34 #[maybe_async::maybe_async]
35 pub(crate) trait PubCrateTrait {
sync_fn()36     fn sync_fn() {}
37 
declare_async(&self)38     async fn declare_async(&self);
39 
async_fn(&self)40     async fn async_fn(&self) {
41         self.declare_async().await
42     }
43 }
44 
45 #[maybe_async::maybe_async(AFIT)]
46 trait AfitTrait {
sync_fn_afit()47     fn sync_fn_afit() {}
48 
declare_async_afit(&self)49     async fn declare_async_afit(&self);
50 
async_fn_afit(&self)51     async fn async_fn_afit(&self) {
52         self.declare_async_afit().await
53     }
54 }
55 
56 #[cfg(not(feature = "is_sync"))]
57 #[maybe_async::must_be_async]
async_fn()58 async fn async_fn() {}
59 
60 #[cfg(not(feature = "is_sync"))]
61 #[maybe_async::must_be_async]
pub_async_fn()62 pub async fn pub_async_fn() {}
63 
64 #[cfg(not(feature = "is_sync"))]
65 #[maybe_async::maybe_async]
pub_crate_async_fn()66 pub(crate) async fn pub_crate_async_fn() {}
67 
68 #[cfg(not(feature = "is_sync"))]
69 #[maybe_async::maybe_async]
unsafe_fn()70 unsafe fn unsafe_fn() {}
71 
72 struct Struct;
73 
74 #[cfg(not(feature = "is_sync"))]
75 #[maybe_async::must_be_async]
76 impl Struct {
sync_fn_inherent()77     fn sync_fn_inherent() {}
78 
declare_async_inherent(&self)79     async fn declare_async_inherent(&self) {}
80 
async_fn_inherent(&self)81     async fn async_fn_inherent(&self) {
82         async { self.declare_async_inherent().await }.await
83     }
84 }
85 
86 #[cfg(not(feature = "is_sync"))]
87 #[maybe_async::must_be_async]
88 impl Trait for Struct {
sync_fn()89     fn sync_fn() {}
90 
declare_async(&self)91     async fn declare_async(&self) {}
92 
async_fn(&self)93     async fn async_fn(&self) {
94         async { self.declare_async().await }.await
95     }
96 }
97 
98 #[cfg(not(feature = "is_sync"))]
99 #[maybe_async::must_be_async(?Send)]
100 impl NotSendTrait for Struct {
declare_async_not_send(&self)101     async fn declare_async_not_send(&self) {}
102 
async_fn_not_send(&self)103     async fn async_fn_not_send(&self) {
104         async { self.declare_async_not_send().await }.await
105     }
106 }
107 #[cfg(not(feature = "is_sync"))]
108 #[maybe_async::must_be_async(AFIT)]
109 impl AfitTrait for Struct {
sync_fn_afit()110     fn sync_fn_afit() {}
111 
declare_async_afit(&self)112     async fn declare_async_afit(&self) {}
113 
async_fn_afit(&self)114     async fn async_fn_afit(&self) {
115         async { self.declare_async_afit().await }.await
116     }
117 }
118 
119 #[cfg(feature = "is_sync")]
main()120 fn main() {}
121 
122 #[cfg(not(feature = "is_sync"))]
123 #[async_std::main]
main()124 async fn main() {
125     let s = Struct;
126     s.declare_async_inherent().await;
127     s.async_fn_inherent().await;
128     s.declare_async().await;
129     s.async_fn().await;
130     s.declare_async_afit().await;
131     s.async_fn_afit().await;
132     async_fn().await;
133     pub_async_fn().await;
134 }
135