pub trait AsyncTryInto<T>: Sized {
type Error: Debug;
// Required method
fn async_try_into<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = Result<T, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait;
}Expand description
Trait for asynchronous fallible conversions into a type T.
This trait provides a method to convert Self into T, potentially returning an error.
§Example
use async_from::{ async_trait, AsyncTryFrom, AsyncTryInto };
use std::num::ParseIntError;
struct MyNumber( u32 );
#[ async_trait ]
impl AsyncTryFrom< String > for MyNumber
{
type Error = ParseIntError;
async fn async_try_from( value : String ) -> Result< Self, Self::Error >
{
let num = value.parse::< u32 >()?;
Ok( MyNumber( num ) )
}
}
#[ tokio::main ]
async fn main()
{
let result : Result< MyNumber, _ > = "42".to_string().async_try_into().await;
match result
{
Ok( my_num ) => println!( "Converted successfully using AsyncTryInto: {}", my_num.0 ),
Err( e ) => println!( "Conversion failed using AsyncTryInto: {:?}", e ),
}
}Required Associated Types§
Required Methods§
Sourcefn async_try_into<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = Result<T, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
fn async_try_into<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = Result<T, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
Asynchronously attempts to convert Self into a value of type T.
§Returns
Result<T, Self::Error>- On success, returns the converted value. On failure, returns an error.
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> AsyncTryInto<U> for T
Blanket implementation of AsyncTryInto for any type that implements AsyncTryFrom.
impl<T, U> AsyncTryInto<U> for T
Blanket implementation of AsyncTryInto for any type that implements AsyncTryFrom.
This implementation allows any type T that implements AsyncTryFrom<U> to also implement AsyncTryInto<U>.