pub mod collections;
pub mod combinators;
#[cfg(feature = "diff")]
pub mod diff;
pub mod error;
pub mod format;
pub mod i18n;
pub mod input;
#[cfg(feature = "openapi")]
pub mod json_schema;
mod macros;
pub mod modifiers;
pub mod object;
pub mod primitives;
pub mod schema;
#[doc(hidden)]
pub use serde_json;
#[doc(hidden)]
pub use serde;
#[cfg(feature = "serialize")]
#[doc(hidden)]
#[macro_export]
macro_rules! __vld_if_serialize {
($($tt:tt)*) => { $($tt)* };
}
#[cfg(not(feature = "serialize"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __vld_if_serialize {
($($tt:tt)*) => {};
}
#[cfg(feature = "openapi")]
#[doc(hidden)]
#[macro_export]
macro_rules! __vld_if_openapi {
($($tt:tt)*) => { $($tt)* };
}
#[cfg(not(feature = "openapi"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __vld_if_openapi {
($($tt:tt)*) => {};
}
#[cfg(feature = "openapi")]
#[doc(hidden)]
#[macro_export]
macro_rules! __vld_nested_schema_fn {
($ty:ty) => {
Some(<$ty>::json_schema as fn() -> $crate::serde_json::Value)
};
}
#[cfg(not(feature = "openapi"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __vld_nested_schema_fn {
($ty:ty) => {
None
};
}
#[cfg(feature = "regex")]
pub use regex_lite;
#[cfg(feature = "derive")]
pub use vld_derive::Validate;
pub fn string() -> primitives::ZString {
primitives::ZString::new()
}
pub fn number() -> primitives::ZNumber {
primitives::ZNumber::new()
}
pub fn boolean() -> primitives::ZBoolean {
primitives::ZBoolean::new()
}
pub fn bytes() -> primitives::ZBytes {
primitives::ZBytes::new()
}
#[cfg(feature = "decimal")]
pub fn decimal() -> primitives::ZDecimal {
primitives::ZDecimal::new()
}
#[cfg(feature = "net")]
pub fn ip_network() -> primitives::ZIpNetwork {
primitives::ZIpNetwork::new()
}
pub fn socket_addr() -> primitives::ZSocketAddr {
primitives::ZSocketAddr::new()
}
pub fn json_value() -> primitives::ZJsonValue {
primitives::ZJsonValue::new()
}
#[cfg(feature = "file")]
pub fn file() -> primitives::ZFile {
primitives::ZFile::new()
}
#[cfg(feature = "std")]
pub fn duration() -> primitives::ZDuration {
primitives::ZDuration::new()
}
#[cfg(feature = "std")]
pub fn path() -> primitives::ZPath {
primitives::ZPath::new()
}
pub fn array<T: schema::VldSchema>(element: T) -> collections::ZArray<T> {
collections::ZArray::new(element)
}
pub fn object() -> object::ZObject {
object::ZObject::new()
}
pub fn nested<T, F>(f: F) -> schema::NestedSchema<T, F>
where
F: Fn(&serde_json::Value) -> Result<T, error::VldError>,
{
schema::NestedSchema::new(f)
}
pub fn nested_named<T, F>(
name: &'static str,
f: F,
json_schema_fn: Option<fn() -> serde_json::Value>,
) -> schema::NestedSchema<T, F>
where
F: Fn(&serde_json::Value) -> Result<T, error::VldError>,
{
schema::NestedSchema::new_named(f, name, json_schema_fn)
}
#[macro_export]
macro_rules! nested {
($ty:ty) => {
$crate::nested_named(
stringify!($ty),
<$ty>::parse_value,
$crate::__vld_nested_schema_fn!($ty),
)
};
}
pub fn literal<T: primitives::IntoLiteral>(val: T) -> primitives::ZLiteral<T> {
primitives::ZLiteral::new(val)
}
pub fn enumeration(variants: &[&str]) -> primitives::ZEnum {
primitives::ZEnum::new(variants)
}
pub fn any() -> primitives::ZAny {
primitives::ZAny::new()
}
#[cfg(feature = "chrono")]
pub fn date() -> primitives::ZDate {
primitives::ZDate::new()
}
#[cfg(feature = "chrono")]
pub fn datetime() -> primitives::ZDateTime {
primitives::ZDateTime::new()
}
pub fn record<V: schema::VldSchema>(value_schema: V) -> collections::ZRecord<V> {
collections::ZRecord::new(value_schema)
}
pub fn map<K: schema::VldSchema, V: schema::VldSchema>(
key_schema: K,
value_schema: V,
) -> collections::ZMap<K, V> {
collections::ZMap::new(key_schema, value_schema)
}
pub fn set<T: schema::VldSchema>(element: T) -> collections::ZSet<T> {
collections::ZSet::new(element)
}
pub fn union<A: schema::VldSchema, B: schema::VldSchema>(a: A, b: B) -> combinators::ZUnion2<A, B> {
combinators::ZUnion2::new(a, b)
}
pub fn union3<A: schema::VldSchema, B: schema::VldSchema, C: schema::VldSchema>(
a: A,
b: B,
c: C,
) -> combinators::ZUnion3<A, B, C> {
combinators::ZUnion3::new(a, b, c)
}
pub fn intersection<A: schema::VldSchema, B: schema::VldSchema>(
a: A,
b: B,
) -> combinators::ZIntersection<A, B> {
combinators::ZIntersection::new(a, b)
}
pub fn discriminated_union(discriminator: impl Into<String>) -> combinators::ZDiscriminatedUnion {
combinators::ZDiscriminatedUnion::new(discriminator)
}
pub fn lazy<T: schema::VldSchema, F: Fn() -> T>(factory: F) -> combinators::ZLazy<T, F> {
combinators::ZLazy::new(factory)
}
pub fn custom<F, T>(check: F) -> combinators::ZCustom<F, T>
where
F: Fn(&serde_json::Value) -> Result<T, String>,
{
combinators::ZCustom::new(check)
}
pub fn preprocess<F, S>(preprocessor: F, schema: S) -> combinators::ZPreprocess<F, S>
where
F: Fn(&serde_json::Value) -> serde_json::Value,
S: schema::VldSchema,
{
combinators::ZPreprocess::new(preprocessor, schema)
}
pub mod prelude {
pub use crate::collections::{ZArray, ZMap, ZRecord, ZSet};
pub use crate::combinators::{
Either, Either3, ZCatch, ZCustom, ZDescribe, ZDiscriminatedUnion, ZIntersection, ZLazy,
ZMessage, ZPipe, ZPreprocess, ZRefine, ZSuperRefine, ZTransform, ZUnion2, ZUnion3,
};
pub use crate::error::{
FieldResult, IssueBuilder, IssueCode, ParseResult, PathSegment, ValidationIssue, VldError,
};
pub use crate::format::{flatten_error, prettify_error, treeify_error};
pub use crate::input::VldInput;
#[cfg(feature = "openapi")]
pub use crate::json_schema::JsonSchema;
pub use crate::modifiers::{ZDefault, ZNullable, ZNullish, ZOptional};
pub use crate::object::ZObject;
#[cfg(feature = "decimal")]
pub use crate::primitives::ZDecimal;
#[cfg(feature = "net")]
pub use crate::primitives::ZIpNetwork;
#[cfg(feature = "file")]
pub use crate::primitives::{FileStorage, ValidatedFile, ZFile};
pub use crate::primitives::{
IntoLiteral, ZAny, ZBoolean, ZBytes, ZEnum, ZInt, ZJsonValue, ZLiteral, ZNumber,
ZSocketAddr, ZString,
};
#[cfg(feature = "chrono")]
pub use crate::primitives::{ZDate, ZDateTime};
#[cfg(feature = "std")]
pub use crate::primitives::{ZDuration, ZPath};
pub use crate::schema::{VldParse, VldSchema};
}