1 unstable release

0.1.0 Nov 17, 2022

#1343 in Asynchronous

MIT license

12KB
160 lines

License Crates.io Docs

derive-tokio-io

Derive AsyncRead and AsyncWrite.

Usage

If the struct has only one field, AsyncRead and AsyncWrite are derived for that field.

use derive_tokio_io::{AsyncRead, AsyncWrite};
use tokio::net::TcpStream;

#[derive(AsyncRead, AsyncWrite)]
struct Wrapper {
    stream: TcpStream,
}

Generics are supported.

use derive_tokio_io::{AsyncRead, AsyncWrite};

#[derive(AsyncRead, AsyncWrite)]
struct Wrapper<IO> {
    stream: IO,
}

If the struct has multiple fields, #[async_read] and #[async_write] must be used once for any field.

use derive_tokio_io::{AsyncRead, AsyncWrite};

#[derive(AsyncRead, AsyncWrite)]
struct Wrapper<R, W> {
    #[async_read]
    reader: R,
    #[async_write]
    writer: W,
}

Everything works the same way for tuple structs.

use derive_tokio_io::{AsyncRead, AsyncWrite};

#[derive(AsyncRead, AsyncWrite)]
struct Wrapper<R, W>(
    #[async_read]
    R,
    #[async_write]
    W,
);

License

This project is licensed under the MIT license.

Dependencies

~1.5MB
~34K SLoC