async-io-map
A lightweight Rust library for transforming data during asynchronous I/O operations.
Table of Contents
Overview
async-io-map
provides wrappers for async readers and writers that allow you to transform data in-flight during I/O operations. The library offers a simple, flexible API that integrates seamlessly with the futures_lite
ecosystem.
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
= "1.12.0" # Required peer dependency
Usage
Reading with Transformation
use AsyncMapReader;
use Cursor;
use AsyncReadExt;
use block_on;
Writing with Transformation
use AsyncMapWriter;
use Cursor;
use AsyncWriteExt;
use block_on;
Features
1. Efficient Buffered Operations
The library uses internal buffering to minimize the number of read/write operations to the underlying I/O source, providing optimal performance even with small read/write calls.
2. Flexible Transformation API
Transform your data with simple closures or implement the MapReadFn
/MapWriteFn
traits for more complex transformations. The transformation logic has full access to modify the data in-place.
3. Zero-Copy Design
The library is designed to minimize allocations and copying, with transformations applied directly to buffers before they're passed to the underlying I/O operations.
4. Support for Trait Extensions
Extends any type implementing AsyncRead
or AsyncWrite
with .map()
and .map_with_capacity()
methods for seamless integration with existing code.
Configuration
Both AsyncMapReader
and AsyncMapWriter
can be configured with custom buffer sizes:
// Create a reader with a 4KB buffer
let reader = with_capacity;
// Create a writer with a 16KB buffer
let writer = with_capacity;
The default buffer size is 8KB, which works well for most use cases. Adjust based on your expected I/O patterns.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please ensure your code passes all tests and follows the project's coding style.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions, issues, or feature requests, please open an issue on the GitHub repository.