-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Applying the '?' expression to an async function doesn't seem to work as intended. #23
Comments
use std::error::Error;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum MyError {
#[error("something went wrong")]
Cool,
}
pub enum Expression {
Literal(&'static str),
Nested(Box<Expression>),
AnotherOne,
}
#[async_recursion::async_recursion]
pub async fn resolve_expression(expression: &Expression) -> Result<i32, Box<dyn Error>> {
match expression {
Expression::Literal(_) => Ok(7),
Expression::Nested(nested) => {
let x = resolve_expression(nested).await?;
Ok(x + 1)
}
Expression::AnotherOne => Err(Box::new(MyError::Cool)),
}
} I'll have a go at fixing this up. |
@myyrakle I still intend to fix this properly, but a temporary workaround might be to explicitly cast your boxed error to #[async_recursion::async_recursion]
pub async fn resolve_expression(expression: &Expression) -> Result<i32, Box<dyn Error>> {
match expression {
Expression::Literal(_) => Ok(7),
Expression::Nested(nested) => {
let x = resolve_expression(nested).await?;
Ok(x + 1)
}
Expression::AnotherOne => Err(Box::new(MyError::Cool) as Box<dyn Error>), // <-- cast error type here
}
} |
Thanks for your kind reply. |
I always use ? expressions.
However, after adding async, an inconvenient error occurs even if i use the method introduced in other documents or use your library.
This is a problem that occurs because the Pin and Box are additionally covered.
Do you know a neat solution to this?
The text was updated successfully, but these errors were encountered: