Open LyunKi opened 2 years ago
Are you requesting to allow async fn
call througth the custom
field in validate
macro ?
@IniterWorker - I'm here to suggest that async fn's can be used in custom
derive annotations. I'm not sure where to start but would be happy to collaborate on it.
any progress on this?
None. A rewrite of the macro has landed on the next branch if someones wants to have a look.
We should also think about if we want to be async framework agnistic or support just tokio
or smol
or others or all of them with features.
Any progress on this? Or any workaround that works with this crate: https://github.com/rambler-digital-solutions/actix-web-validator ? Supporting only non async methods makes this crate unusable for something like username validation if an async connection is used to the database.
This is what I've been doing if I have a db/async validator, here is a dummy example, hope it helps until this is fixed.:
#[derive(Deserialize, Validate)]
pub struct SignupForm {
#[validate(length(min = 3))]
pub username: String,
#[validate(email)]
pub email: String,
}
let mut validation_errors = ValidationErrors::new();
if let Err(form_validation_errors) = signup_form.validate() {
validation_errors = form_validation_errors;
}
let user_result =
User::create(&signup_form.username, &signup_form.email, &app_state.conn).await;
if user_result.is_err() {
validation_errors.add(
"general",
ValidationError::new("A user with this email or username already exists."),
);
} else {
Token::send_auth_token_email(user_result.unwrap().id, &app_state.conn).await?;
}
In some cases, we may need an async validator, so that we can call value.validate_async(xxx) which just like this js lib https://github.com/yiminghe/async-validator/