• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(dead_code, unused_variables)]
2 
3 /// InnerClient differ a lot between sync and async.
4 #[maybe_async::maybe_async]
5 trait Trait {
maybe_async_fn()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 {
maybe_async_fn()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 {
maybe_async_fn()23     async fn maybe_async_fn() { }
24 }
25 
26 impl Struct {
27     #[maybe_async::maybe_async]
another_maybe_async_fn()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]
main()36 fn main() {
37     let _ = Struct::another_maybe_async_fn();
38 }
39 
40 #[maybe_async::async_impl]
41 #[tokio::main]
main()42 async fn main() {
43     let _ = Struct::another_maybe_async_fn().await;
44 }
45