Guides

Migration

Breaking changes per release, with before/after code.

From 0.7 to 0.8

Crates merged into six

The 30 crates became six. Every integration is a module of a group crate, behind a feature; no feature is on by default, so name what you use. Several majors of one library (ntex 3 / 4, utoipa 5 / 6, sqlx 0.8 / 0.9, …) are separate features and modules that can be enabled together. Items inside each module keep their 0.7 names.

0.7 crate0.8 crate, featurePath
vld-axum, vld-actix, vld-poem, vld-rocket, vld-salvo, vld-warp, vld-rama, vld-tower, vld-tonicvld-web, <name>vld_web::<name>
vld-ntexvld-web, ntex-3 / ntex-4 (+ ntex-compress)vld_web::ntex3 / ntex4
vld-http-commonvld-webvld_web::common
vld-utoipavld-openapi, utoipa-5 / utoipa-6vld_openapi::utoipa5 / utoipa6
vld-schemars, vld-aidevld-openapi, schemars-0 / schemars-1vld_openapi::schemars0 / schemars1, vld_openapi::validator
vld-ts, vld-fakevld, ts / fakevld::ts, vld::fake
vld-leptos, vld-dioxusvldvld::form
vld-sqlxvld-data, sqlx-0_8 / sqlx-0_9 + sqlite / postgres / mysqlvld_data::sqlx08 / sqlx09
vld-dieselvld-data, diesel + backendvld_data::diesel
vld-seavld-data, sea-orm-1 / sea-orm-2 (+ with-*)vld_data::sea1 / sea2
vld-surrealdbvld-datavld_data::surrealdb
vld-redisvld-data, redis-0 / redis-1 (+ redis-aio, redis-aio-tokio)vld_data::redis0 / redis1
vld-lapinvld-data, lapin-2 / lapin-3 / lapin-4vld_data::lapin2 / lapin3 / lapin4
vld-configvld-app, config-rs / figmentvld_app::config
vld-clapvld-app, clapvld_app::clap
vld-taurivld-appvld_app::tauri
vld-integration-commonvldvld::form, vld::error::{format_path, flatten_issues}

Former defaults you now have to name: vld-ntex → ntex-4, vld-utoipa → utoipa-5, vld-schemars / vld-aide → schemars-0, vld-sqlx → sqlx-0_8 + sqlite, vld-diesel → diesel + sqlite, vld-sea → sea-orm-1, vld-redis → redis-0, vld-lapin → lapin-2, vld-config → config-rs. vld-redis's aio / aio-tokio are redis-aio / redis-aio-tokio; vld-ntex's compress is ntex-compress.

Macros moved from the crate root to their module: vld_openapi::utoipa5::impl_to_schema!, vld_openapi::schemars1::impl_json_schema!, vld::ts::impl_to_zod!, vld::fake::impl_fake!, vld::form::validate_args!, vld_web::tonic::impl_validate!, vld_data::sea1::impl_vld_before_save!, vld_data::surrealdb::validate_fields! (full list in the changelog).

Cargo.toml

# 0.7
vld-axum = "0.7"
vld-actix = "0.7"
vld-sqlx = "0.7"                      # sqlx 0.8 + sqlite by default
vld-utoipa = "0.7"                    # utoipa 5 by default
vld-leptos = "0.7"
vld-ts = "0.7"

# 0.8
vld = { version = "0.8", features = ["ts"] }
vld-web = { version = "0.8", features = ["axum", "actix"] }
vld-data = { version = "0.8", features = ["sqlx-0_8", "sqlite"] }
vld-openapi = { version = "0.8", features = ["utoipa-5"] }

Imports

// 0.7                                        // 0.8
use vld_axum::{VldJson, VldQuery};            use vld_web::axum::{VldJson, VldQuery};
use vld_actix::{VldJson, VldBodyLimit};       use vld_web::actix::{VldJson, VldBodyLimit};
use vld_sqlx::prelude::*;                     use vld_data::sqlx08::prelude::*;
use vld_utoipa::impl_to_schema;               use vld_openapi::utoipa5::impl_to_schema;
vld_utoipa::impl_to_schema!(User);            vld_openapi::utoipa5::impl_to_schema!(User);
vld_leptos::validate_args! { .. }             vld::form::validate_args! { .. }
vld_leptos::check_field(&v, &schema)          vld::form::check_field(&v, &schema)
use vld_ts::{impl_to_zod, ToZod};             use vld::ts::{impl_to_zod, ToZod};

vld-leptos / vld-dioxus had a prelude; vld::form has none, import the items you use.

vld_data::lapin*: VldLapinError

VldLapinError is #[non_exhaustive] and has a new variant NotSettled: on lapin 3 / 4 an ack / nack / reject that sends nothing (delivery already settled, channel closed) is now an error instead of a silent Ok. Add a _ => arm to exhaustive matches.

0.6 → 0.7

vld-tauri: TauriIssue

TauriIssue has two new public fields, code (IssueCode::key()) and params (BTreeMap<String, String>). Struct literals must set them; deserializing old JSON still works (both default to empty).

TauriIssue { path, message, code: String::new(), params: Default::default() }

0.5 → 0.6

Regular expressions

regex-lite is no longer part of the public API: string().regex(Regex) / regex_msg and the vld::regex_lite re-export are gone. Use pattern (same regex feature, same issue code invalid_string / Regex, same JSON Schema pattern):

// before
vld::string().regex(vld::regex_lite::Regex::new(r"^[A-Z]{3}$").unwrap())
// after
vld::string().pattern(r"^[A-Z]{3}$")
// an invalid pattern you want to handle instead of panicking
vld::string().pattern(vld::rules::Pattern::new(src)?)

For checks that are easier in Rust than in a regex, see custom rules.

optional, nullable, nullish

  • nullable() fields are now required: an absent key fails with missing_field (a present null is still None). Use nullish() where the key may be left out.
  • optional() no longer adds null to its JSON Schema (TypeScript x?: T); parsing still accepts null.
  • nullable() is in required in JSON Schema (TypeScript x: T | null).

See the table.

Unions serialize as plain values

Either / Either3 are serde untagged now: {"Left": "x"} becomes "x". Code that stored or sent the tagged form must use the bare value.

Removed

RemovedUse
features serialize, deserializenothing (serde support is always on): drop them from features
ZFloat::finite()nothing: JSON has no NaN / infinity
ZObject::field_schema()field()
ZObject::deep_partial()partial() on each nested object
vld-actix::VldJsonErrorVldActixError
vld-diesel::validate_update, vld-sqlx::validate_updatevalidate_insert
vld-surrealdb::validate_recordvalidate_content
vld-http-common::ValidationIssueWithCode / format_issues_with_codeValidationIssue / format_issues
vld-http-common::format_json_parse_error / format_utf8_errorVldHttpError::parse (the adapters already answer with it)
vld-tower::try_validated, vld-rama::try_validatedvalidated()
vld-tauri::validate_event / validate_state / validate_plugin_config / validate_channel_messagevalidate
impl_to_lapin!, impl_to_redis!, impl_to_redis_async!LapinChannel::new(ch), RedisConn::new(conn), AsyncRedisConn::new(conn)
vld-utoipa::impl_into_params!, impl_to_schema_query!, impl_to_schema_path!#[into_params(parameter_in = ...)] + impl_to_schema!(T), or impl_to_schema!(T, query)

Custom DynSchema impls

DynSchema has a new required method dyn_parse_missing (implemented for every VldSchema automatically). Only a hand-written DynSchema impl needs it: return what an absent object key should give.

0.4 → 0.5

See the 0.5.0 entry in the changelog (its "Migration from 0.4" section).