ic_dbms_api/
validate.rs

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