Skip to main content

wasm_dbms_api/dbms/
validate.rs

1//! This module contains all the built-in validations which can be applied to columns.
2//!
3//! Each validation function takes a [`Value`](crate::dbms::value::Value) as input and returns a `DbmsResult<()>` indicating
4//! whether the value passes the validation or not.
5
6mod case;
7mod chain;
8mod color;
9mod email;
10mod locale;
11mod phone;
12mod strlen;
13mod web;
14
15pub use self::case::{CamelCaseValidator, KebabCaseValidator, SnakeCaseValidator};
16pub use self::chain::ValidatorChain;
17pub use self::color::RgbColorValidator;
18pub use self::email::EmailValidator;
19pub use self::locale::{CountryIso639Validator, CountryIso3166Validator};
20pub use self::phone::PhoneNumberValidator;
21pub use self::strlen::{MaxStrlenValidator, MinStrlenValidator, RangeStrlenValidator};
22pub use self::web::{MimeTypeValidator, UrlValidator};
23use crate::error::DbmsResult;
24
25/// Trait for validating [`crate::prelude::Value`]s.
26pub trait Validate {
27    /// Validates the given [`crate::prelude::Value`].
28    ///
29    /// In case of error it should return a [`crate::prelude::DbmsError::Validation`] error.
30    fn validate(&self, value: &crate::prelude::Value) -> DbmsResult<()>;
31}