File tree 5 files changed +53
-3
lines changed
5 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 25
25
- name : Build
26
26
run : cargo build
27
27
- name : Run tests
28
- run : cargo test -- --skip ui_compile_fail
28
+ if : matrix.rust-version != '1.37'
29
+ run : cargo test --all -- --skip ui_compile_fail
29
30
- name : Run compile-fail tests
30
31
if : matrix.rust-version == 'stable'
31
32
run : cargo test -- ui_compile_fail
33
+ - name : Run tests (MSRV)
34
+ if : matrix.rust-version == '1.37'
35
+ run : cargo test -- --skip ui_compile_fail
Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " auto_impl"
3
- version = " 0.5 .0"
3
+ version = " 1.0 .0"
4
4
authors = [
5
5
" Ashley Mannix <[email protected] >" ,
6
6
" Lukas Kalbertodt <[email protected] >" ,
@@ -16,6 +16,10 @@ autotests = true
16
16
edition = " 2018"
17
17
rust-version = " 1.37"
18
18
19
+ [workspace ]
20
+ members = [
21
+ " examples/async_await"
22
+ ]
19
23
20
24
[lib ]
21
25
proc-macro = true
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ some common smart pointers and closures.
5
5
6
6
# Usage
7
7
8
- This library requires Rust 1.37.0 or newer.
8
+ This library requires Rust 1.37.0 or newer. This library doesn't leave any public API in your code.
9
9
10
10
Add ` auto_impl ` to your ` Cargo.toml ` and just use it in your crate:
11
11
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " auto_impl_async_await_example"
3
+ version = " 0.0.0"
4
+ publish = false
5
+ edition = " 2018"
6
+
7
+ [dependencies ]
8
+ auto_impl = { path = " ../../" }
9
+ async-trait = " 0.1"
10
+ async-std = { version = " 1" , features = [" attributes" ] }
Original file line number Diff line number Diff line change
1
+ use std:: time:: Duration ;
2
+ use async_std:: task;
3
+
4
+ use async_trait:: async_trait;
5
+ use auto_impl:: auto_impl;
6
+
7
+ // Note the order of the attributes here:
8
+ // `#[async_trait]` must appear first
9
+ #[ async_trait]
10
+ #[ auto_impl( & , Box , Arc ) ]
11
+ trait Component {
12
+ async fn run ( & self ) ;
13
+ }
14
+
15
+ struct WaitABit ( Duration ) ;
16
+
17
+ #[ async_trait]
18
+ impl Component for WaitABit {
19
+ async fn run ( & self ) {
20
+ task:: sleep ( self . 0 ) . await ;
21
+ }
22
+ }
23
+
24
+ async fn run_async ( a : impl Component ) {
25
+ a. run ( ) . await ;
26
+ }
27
+
28
+ #[ async_std:: main]
29
+ async fn main ( ) {
30
+ // We can treat our `Box<WaitABit>` as an `impl Component` directly
31
+ run_async ( Box :: new ( WaitABit ( Duration :: from_secs ( 1 ) ) ) ) . await ;
32
+ }
You can’t perform that action at this time.
0 commit comments