File tree 4 files changed +25
-26
lines changed
4 files changed +25
-26
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ md5 = "0.7.0"
37
37
rand = { version = " 0.8.5" , features = [" small_rng" ] }
38
38
structopt = " 0.3.26"
39
39
tempfile = " 3.3.0"
40
+ tokio = { version = " 1" , features = [" rt-multi-thread" , " macros" ] }
40
41
41
42
# deps for tftpd-targz.rs
42
43
async-compression = { version = " 0.3.15" , features = [" gzip" , " futures-io" ] }
Original file line number Diff line number Diff line change @@ -33,21 +33,21 @@ Features:
33
33
use async_tftp :: server :: TftpServerBuilder ;
34
34
use async_tftp :: Result ;
35
35
36
- fn main () -> Result <()> {
37
- smol :: block_on (async { // or any other runtime/executor
38
- let tftpd = TftpServerBuilder :: with_dir_ro (" ." )? . build (). await ? ;
39
- tftpd . serve (). await ? ;
40
- Ok (())
41
- })
36
+ #[tokio:: main] // or any other runtime/executor
37
+ async fn main () -> Result <()> {
38
+ let tftpd = TftpServerBuilder :: with_dir_ro (" ." )? . build (). await ? ;
39
+ tftpd . serve (). await ? ;
40
+ Ok (())
42
41
}
43
42
```
44
43
45
44
Add in ` Cargo.toml ` :
46
45
47
46
``` toml
48
47
[dependencies ]
49
- smol = " 1" # or any other runtime/executor
50
48
async-tftp = " 0.3"
49
+ # or any other runtime/executor
50
+ tokio = { version = " 1" , features = [" rt-multi-thread" , " macros" ] }
51
51
```
52
52
53
53
## Running examples with cargo
Original file line number Diff line number Diff line change 1
1
use anyhow:: Result ;
2
2
use async_tftp:: server:: TftpServerBuilder ;
3
- use futures_lite:: future:: block_on;
4
3
4
+ #[ tokio:: main]
5
5
fn main ( ) -> Result < ( ) > {
6
6
fern:: Dispatch :: new ( )
7
7
. level ( log:: LevelFilter :: Info )
@@ -10,17 +10,15 @@ fn main() -> Result<()> {
10
10
. apply ( )
11
11
. expect ( "Failed to initialize logger" ) ;
12
12
13
- block_on ( async {
14
- let tftpd = TftpServerBuilder :: with_dir_ro ( "." ) ?
15
- . bind ( "0.0.0.0:6969" . parse ( ) . unwrap ( ) )
16
- // Workaround to handle cases where client is behind VPN
17
- . block_size_limit ( 1024 )
18
- . build ( )
19
- . await ?;
13
+ let tftpd = TftpServerBuilder :: with_dir_ro ( "." ) ?
14
+ . bind ( "0.0.0.0:6969" . parse ( ) . unwrap ( ) )
15
+ // Workaround to handle cases where client is behind VPN
16
+ . block_size_limit ( 1024 )
17
+ . build ( )
18
+ . await ?;
20
19
21
- log:: info!( "Listening on: {}" , tftpd. listen_addr( ) ?) ;
22
- tftpd. serve ( ) . await ?;
20
+ log:: info!( "Listening on: {}" , tftpd. listen_addr( ) ?) ;
21
+ tftpd. serve ( ) . await ?;
23
22
24
- Ok ( ( ) )
25
- } )
23
+ Ok ( ( ) )
26
24
}
Original file line number Diff line number Diff line change 27
27
//! use async_tftp::server::TftpServerBuilder;
28
28
//! use async_tftp::Result;
29
29
//!
30
- //! fn main() -> Result<()> {
31
- //! smol::block_on(async { // or any other runtime/executor
32
- //! let tftpd = TftpServerBuilder::with_dir_ro(".")?.build().await?;
33
- //! tftpd.serve().await?;
34
- //! Ok(())
35
- //! })
30
+ //! #[tokio::main] // or any other runtime/executor
31
+ //! async fn main() -> Result<()> {
32
+ //! let tftpd = TftpServerBuilder::with_dir_ro(".")?.build().await?;
33
+ //! tftpd.serve().await?;
34
+ //! Ok(())
36
35
//! }
37
36
//! ```
38
37
//!
39
38
//! Add in `Cargo.toml`:
40
39
//!
41
40
//! ```toml
42
41
//! [dependencies]
43
- //! smol = "1" # or any other runtime/executor
44
42
//! async-tftp = "0.3"
43
+ //! # or any other runtime/executor
44
+ //! tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
45
45
//! ```
46
46
//!
47
47
//! [smol]: https://docs.rs/smol
You can’t perform that action at this time.
0 commit comments