Debian Codegraph @

third_party/rust/maybe-async/tests/ui/01-maybe-async.rs

raw
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(AFIT)]
39 trait AfitTrait {
40 fn sync_fn_afit() {}
41
42 async fn declare_async_afit(&self);
43
44 async fn async_fn_afit(&self) {
45 self.declare_async_afit().await
46 }
47 }
48
49 #[maybe_async]
50 async fn async_fn() {}
51
52 #[maybe_async]
53 pub async fn pub_async_fn() {}
54
55 #[maybe_async]
56 pub(crate) async fn pub_crate_async_fn() {}
57
58 #[maybe_async]
59 unsafe fn unsafe_fn() {}
60
61 struct Struct;
62
63 #[maybe_async]
64 impl Struct {
65 fn sync_fn_inherent() {}
66
67 async fn declare_async_inherent(&self) {}
68
69 async fn async_fn_inherent(&self) {
70 async { self.declare_async_inherent().await }.await
71 }
72 }
73
74 #[maybe_async]
75 impl Trait for Struct {
76 fn sync_fn() {}
77
78 async fn declare_async(&self) {}
79
80 async fn async_fn(&self) {
81 async { self.declare_async().await }.await
82 }
83 }
84
85 #[maybe_async(AFIT)]
86 impl AfitTrait for Struct {
87 fn sync_fn_afit() {}
88
89 async fn declare_async_afit(&self) {}
90
91 async fn async_fn_afit(&self) {
92 async { self.declare_async_afit().await }.await
93 }
94 }
95
96 #[cfg(feature = "is_sync")]
97 fn main() -> std::result::Result<(), ()> {
98 let s = Struct;
99 s.declare_async_inherent();
100 s.async_fn_inherent();
101 s.declare_async();
102 s.async_fn();
103 s.declare_async_afit();
104 s.async_fn_afit();
105 async_fn();
106 pub_async_fn();
107 Ok(())
108 }
109
110 #[cfg(not(feature = "is_sync"))]
111 #[async_std::main]
112 async fn main() {
113 let s = Struct;
114 s.declare_async_inherent().await;
115 s.async_fn_inherent().await;
116 s.declare_async().await;
117 s.async_fn().await;
118 s.declare_async_afit().await;
119 s.async_fn_afit().await;
120 async_fn().await;
121 pub_async_fn().await;
122 }