Skip to main content

Crate vld_salvo

Crate vld_salvo 

Source
Expand description

§vld-salvo — Salvo integration for vld

Validation extractors for Salvo. All extractors implement Extractible and can be used directly as #[handler] function parameters — just like Salvo’s built-in JsonBody or PathParam.

ExtractorSource
VldJson<T>JSON request body
VldQuery<T>URL query parameters
VldForm<T>URL-encoded form body
VldPath<T>Path parameters
VldHeaders<T>HTTP headers
VldCookie<T>Cookie values

All extractors return 422 Unprocessable Entity on validation failure.

§Quick Example

use salvo::prelude::*;
use vld_salvo::prelude::*;

vld::schema! {
    #[derive(Debug, Clone, serde::Serialize)]
    pub struct CreateUser {
        pub name: String  => vld::string().min(2),
        pub email: String => vld::string().email(),
    }
}

// VldJson<T> is used as a handler parameter — no manual extraction needed!
#[handler]
async fn create(body: VldJson<CreateUser>, res: &mut Response) {
    res.render(Json(serde_json::json!({"name": body.name})));
}

Modules§

prelude
Prelude — import everything you need.

Structs§

VldCookie
Salvo extractor that validates cookie values from the Cookie header.
VldForm
Salvo extractor that validates URL-encoded form bodies.
VldHeaders
Salvo extractor that validates HTTP headers.
VldJson
Salvo extractor that validates JSON request bodies.
VldPath
Salvo extractor that validates path parameters.
VldQuery
Salvo extractor that validates URL query parameters.
VldSalvoError
Error type for vld validation failures in Salvo handlers.