derive-io
A Rust crate that provides derive macros for implementing sync and async I/O traits on structs and enums (including Tokio, stdlib I/O, and more).
Supported traits
#[derive(Read)]:std::io::Read#[derive(Write)]:std::io::Write#[derive(AsyncRead)]:tokio::io::AsyncRead#[derive(AsyncWrite)]:tokio::io::AsyncWrite#[derive(AsFileDescriptor)]:std::os::fd::{AsFd, AsRawFd}std::os::windows::io::{AsHandle, AsRawHandle}
#[derive(AsSocketDescriptor)]:std::os::fd::{AsFd, AsRawFd}std::os::windows::io::{AsSocket, AsRawSocket}
Features
- Derive I/O traits for structs and enums
- Support for both named and tuple structs
- Support for enums with multiple variants
- Support for split read/write streams
- Support for generic types
- Individual methods can be overridden with custom implementations
- Support for
as_reforderefattribute on fields to delegate to the inner type- Note: for traits requiring a pinned-self (ie: async read/write), the holder
type must be
Unpin!
- Note: for traits requiring a pinned-self (ie: async read/write), the holder
type must be
Tokio
use *;
use ;
Generic types are supported. The generated implementations will automatically
add a where clause to the impl block for each stream type.
use ;
Override one method in the write implementation:
use ;