async-reciprocals 0.1.0

A utility library for asynchronous fallible conversion and reciprocals in Rust.
Documentation
  • Coverage
  • 58.33%
    7 out of 12 items documented1 out of 1 items with examples
  • Size
  • Source code size: 52.19 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.92 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jfaleiro

async-reciprocals

A utility library for asynchronous fallible conversion and reciprocals in Rust.

Overview

async-reciprocals provides tools for handling bidirectional asynchronous conversions between different types in Rust. It leverages Tokio for asynchronous operations, making it suitable for high-performance applications that need type conversions in non-blocking contexts.

Features

  • Asynchronous type conversion utilities
  • Built on Tokio runtime for efficient async operations
  • Simple API for bidirectional conversions
  • Designed for Rust's async/await ecosystem

Installation

Add this to your Cargo.toml:

[dependencies]
async-reciprocals = "0.1.0"

Usage

Basic example:

use async_reciprocals::{AsyncTryFrom, AsyncTryInto};
use tokio;
use std::error::Error;

// Define a simple source type
struct UserInput {
    data: String
}

// Define a target type
struct ProcessedData {
    value: String
}

// Implement async conversion from UserInput to ProcessedData
#[async_trait::async_trait]
impl AsyncTryFrom<UserInput> for ProcessedData {
    type Error = Box<dyn Error + Send + Sync>;

    async fn async_try_from(input: UserInput) -> Result<Self, Self::Error> {
        // Simulate some async processing
        tokio::time::sleep(std::time::Duration::from_millis(100)).await;
        
        // Convert the input to processed data
        Ok(ProcessedData {
            value: input.data.to_uppercase()
        })
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a user input
    let user_input = UserInput {
        data: "hello world".to_string()
    };
    
    // Convert it to processed data using AsyncTryInto (available through blanket impl)
    let processed: ProcessedData = user_input.async_try_into().await?;
    
    // Verify the conversion worked
    println!("Converted '{}' to '{}'", "hello world", processed.value);
    assert_eq!(processed.value, "HELLO WORLD");
    
    println!("Async conversion successful!");
    Ok(())
}

Requirements

  • Rust 2024 edition
  • Tokio runtime

Development

To contribute to this project:

  1. Clone the repository
  2. Install dependencies with cargo build
  3. Run tests with cargo test

License

This project is licensed under the GNU Lesser General Public License v2.1 (LGPL-2.1). See the LICENSE file for details.

Contributing

Contributions are welcome. Feel free to submit a Pull Request.