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§
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.