derive-tokio-io

Crates.ioderive-tokio-io
lib.rsderive-tokio-io
version0.1.0
sourcesrc
created_at2022-11-17 08:05:18.022294
updated_at2022-11-17 08:05:18.022294
descriptionDerive AsyncRead and AsyncWrite.
homepagehttps://github.com/programatik29/derive-tokio-io
repositoryhttps://github.com/programatik29/derive-tokio-io
max_upload_size
id717046
size13,650
Eray Karatay (programatik29)

documentation

README

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.

Commit count: 4

cargo fmt