Trait AsyncInto

Source
pub trait AsyncInto<T>: Sized {
    // Required method
    fn async_into<'async_trait>(
        self,
    ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Trait for asynchronous conversions into a type T.

This trait provides a method to convert Self into T asynchronously.

§Example

use async_from::{ async_trait, AsyncFrom, AsyncInto };

struct MyNumber( u32 );

#[ async_trait ]
impl AsyncFrom< String > for MyNumber
{
  async fn async_from( value : String ) -> Self
  {
    let num = value.parse::< u32 >().unwrap_or( 0 );
    MyNumber( num )
  }
}

#[ tokio::main ]
async fn main()
{
  let num : MyNumber = "42".to_string().async_into().await;
  println!( "Converted: {}", num.0 );
}

Required Methods§

Source

fn async_into<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
where Self: 'async_trait,

Asynchronously converts Self into a value of type T.

§Returns
  • T - The converted value.

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, U> AsyncInto<U> for T
where U: AsyncFrom<T> + Send, T: Send,

Blanket implementation of AsyncInto for any type that implements AsyncFrom.

This implementation allows any type T that implements AsyncFrom<U> to also implement AsyncInto<U>.