Expand description
§vld-diesel — Diesel integration for the vld validation library
Validate data before inserting into the database, and use strongly-typed validated column types.
§Quick Start
ⓘ
use vld_diesel::prelude::*;
// 1. Define a vld schema for your insertable struct
vld::schema! {
#[derive(Debug)]
pub struct NewUserSchema {
pub name: String => vld::string().min(1).max(100),
pub email: String => vld::string().email(),
}
}
// 2. Wrap your Diesel Insertable with Validated
let new_user = NewUser { name: "Alice".into(), email: "alice@example.com".into() };
let validated = Validated::<NewUserSchema, _>::new(new_user)?;
// 3. Insert — the inner value is guaranteed to be valid
diesel::insert_into(users::table)
.values(validated.inner())
.execute(&mut conn)?;§Validated column types
Use VldText for columns that must always satisfy a validation schema:
ⓘ
use vld_diesel::VldText;
let email = VldText::<EmailSchema>::new("user@example.com")?;Re-exports§
pub use vld;
Modules§
Structs§
- Validated
- A wrapper that proves its inner value has been validated against schema
S. - VldInt
- A validated integer column type.
- VldText
- A validated text column type.
Enums§
- VldDiesel
Error - Error returned by
vld-dieseloperations.
Functions§
- validate_
insert - Validate a value against schema
Sbefore inserting. - validate_
row - Validate a row loaded from the database against schema
S. - validate_
update - Alias for
validate_insert— same logic applies to updates.