Trait AsyncTryFrom

Source
pub trait AsyncTryFrom<T>: Sized {
    type Error;

    // Required method
    fn async_try_from<'async_trait>(
        value: T,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Enables asynchronous trait methods by generating boilerplate code for async fn in traits

This macro allows defining async methods in traits, which is not natively supported in Rust. It automatically generates the necessary associated types and implementation details to make async trait methods work across different async runtimes.

§Examples

Required Associated Types§

Required Methods§

Source

fn async_try_from<'async_trait>( value: T, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Send> AsyncTryFrom<T> for T

Provides a trivial implementation of AsyncTryFrom for a type converting to itself.

This implementation allows any Send type to be converted asynchronously to itself without any possibility of failure, always returning Ok(value).

§Type Parameters

  • T: The type being converted, which must implement Send

§Returns

Always returns Ok(value) with an Infallible error type, representing a guaranteed successful conversion