Skip to content

Commit bc8eed8

Browse files
committed
chore: Use tokio in examples
1 parent 5af9db6 commit bc8eed8

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ md5 = "0.7.0"
3737
rand = { version = "0.8.5", features = ["small_rng"] }
3838
structopt = "0.3.26"
3939
tempfile = "3.3.0"
40+
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
4041

4142
# deps for tftpd-targz.rs
4243
async-compression = { version = "0.3.15", features = ["gzip", "futures-io"] }

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ Features:
3333
use async_tftp::server::TftpServerBuilder;
3434
use async_tftp::Result;
3535

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(())
4241
}
4342
```
4443

4544
Add in `Cargo.toml`:
4645

4746
```toml
4847
[dependencies]
49-
smol = "1" # or any other runtime/executor
5048
async-tftp = "0.3"
49+
# or any other runtime/executor
50+
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
5151
```
5252

5353
## Running examples with cargo

examples/tftpd-dir.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use async_tftp::server::TftpServerBuilder;
3-
use futures_lite::future::block_on;
43

4+
#[tokio::main]
55
fn main() -> Result<()> {
66
fern::Dispatch::new()
77
.level(log::LevelFilter::Info)
@@ -10,17 +10,15 @@ fn main() -> Result<()> {
1010
.apply()
1111
.expect("Failed to initialize logger");
1212

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?;
2019

21-
log::info!("Listening on: {}", tftpd.listen_addr()?);
22-
tftpd.serve().await?;
20+
log::info!("Listening on: {}", tftpd.listen_addr()?);
21+
tftpd.serve().await?;
2322

24-
Ok(())
25-
})
23+
Ok(())
2624
}

src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727
//! use async_tftp::server::TftpServerBuilder;
2828
//! use async_tftp::Result;
2929
//!
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(())
3635
//! }
3736
//! ```
3837
//!
3938
//! Add in `Cargo.toml`:
4039
//!
4140
//! ```toml
4241
//! [dependencies]
43-
//! smol = "1" # or any other runtime/executor
4442
//! async-tftp = "0.3"
43+
//! # or any other runtime/executor
44+
//! tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
4545
//! ```
4646
//!
4747
//! [smol]: https://docs.rs/smol

0 commit comments

Comments
 (0)