validate_seq_async

Function validate_seq_async 

Source
pub async fn validate_seq_async<T, E, F, Fut>(
    initial: T,
    validators: impl IntoIterator<Item = F>,
) -> Validation<E, T>
where F: FnOnce(T) -> Fut, Fut: Future<Output = Validation<E, T>>,
Expand description

Runs async validations sequentially, where each validation depends on the previous result.

Stops at the first invalid result and returns accumulated errors.

§Example

use error_rail::prelude_async::*;

async fn validate_order(order_id: u64) -> Validation<OrderError, Order> {
    validate_seq_async(
        order_id,
        [
            |id| async move { fetch_order(id).await },
            |order| async move { validate_inventory(&order).await },
            |order| async move { validate_payment(&order).await },
        ],
    )
    .await
}