Debian Codegraph @

third_party/rust/maybe-async/tests/ui/06-sync_impl_async_impl.rs

raw
1 #![allow(dead_code, unused_variables)]
2
3 /// InnerClient differ a lot between sync and async.
4 #[maybe_async::maybe_async]
5 trait Trait {
6 async fn maybe_async_fn();
7 }
8
9 /// The higher level API for end user.
10 pub struct Struct;
11
12 /// Synchronous implementation, only compiles when `is_sync` feature is off.
13 /// Else the compiler will complain that *request is defined multiple times* and
14 /// blabla.
15 #[maybe_async::sync_impl]
16 impl Trait for Struct {
17 fn maybe_async_fn() { }
18 }
19
20 /// Asynchronous implementation, only compiles when `is_sync` feature is off.
21 #[maybe_async::async_impl]
22 impl Trait for Struct {
23 async fn maybe_async_fn() { }
24 }
25
26 impl Struct {
27 #[maybe_async::maybe_async]
28 async fn another_maybe_async_fn() {
29 Self::maybe_async_fn().await
30 // When `is_sync` is toggle on, this block will compiles to:
31 // Self::maybe_async_fn()
32 }
33 }
34
35 #[maybe_async::sync_impl]
36 fn main() {
37 let _ = Struct::another_maybe_async_fn();
38 }
39
40 #[maybe_async::async_impl]
41 #[tokio::main]
42 async fn main() {
43 let _ = Struct::another_maybe_async_fn().await;
44 }