#async-io #tokio #async #fd #io

tokio-fd

Non-blocking Read and Write a Linux File Descriptor

3 releases (breaking)

0.3.0 Jan 6, 2021
0.2.1 Nov 20, 2020
0.2.0 Nov 19, 2020
0.1.0 Feb 11, 2020

#390 in Unix APIs

Download history 5580/week @ 2024-12-14 1157/week @ 2024-12-21 1435/week @ 2024-12-28 4979/week @ 2025-01-04 5157/week @ 2025-01-11 5162/week @ 2025-01-18 4765/week @ 2025-01-25 4129/week @ 2025-02-01 4298/week @ 2025-02-08 3655/week @ 2025-02-15 4120/week @ 2025-02-22 4936/week @ 2025-03-01 5580/week @ 2025-03-08 4894/week @ 2025-03-15 6262/week @ 2025-03-22 4915/week @ 2025-03-29

22,518 downloads per month
Used in 18 crates (9 directly)

MIT/Apache

7KB
92 lines

Non-blocking Read and Write a Linux/Unix File Descriptor

Crates.io

Example

use std::convert::TryFrom;
use std::io::Result;

use tokio::prelude::*;
use tokio_fd::AsyncFd;

#[tokio::main]
async fn main() -> Result<()> {
    let mut stdin = AsyncFd::try_from(libc::STDIN_FILENO)?;
    let mut stdout = AsyncFd::try_from(libc::STDOUT_FILENO)?;
    let mut buf = vec![0; 1024];

    while let Ok(n) = stdin.read(&mut buf).await {
        stdout.write(&buf[..n]).await?;
    }
    Ok(())
}

License

This project is licensed under either of

at your option.

Dependencies

~2–10MB
~94K SLoC