async-reciprocals

Crates.ioasync-reciprocals
lib.rsasync-reciprocals
version0.1.0
created_at2025-04-01 22:11:21.838389+00
updated_at2025-04-01 22:11:21.838389+00
descriptionA utility library for asynchronous fallible conversion and reciprocals in Rust.
homepage
repositoryhttps://github.com/jfaleiro/async-reciprocals
max_upload_size
id1615675
size52,749
(jfaleiro)

documentation

https://docs.rs/async-reciprocals

README

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.

Commit count: 0

cargo fmt