Skip to main content

ic_dbms_api/dbms/
sanitize.rs

1//! This module contains all the built-in sanitizers which can be applied to columns.
2//!
3//! Each validation function takes a [`crate::prelude::Value`] as input and returns a `IcDbmsResult<crate::prelude::Value>` with the sanitized
4//! value or an error if the value could not be sanitized.
5//!
6//! This module contains the [`Sanitize`] trait which should be implemented by all sanitizers.
7
8mod clamp;
9mod collapse_whitespace;
10mod lowercase;
11mod null_if_empty;
12mod round_to_scale;
13mod slug_sanitizer;
14mod timezone;
15mod trim;
16mod uppercase;
17mod url_encoding;
18
19pub use self::clamp::{ClampSanitizer, ClampUnsignedSanitizer};
20pub use self::collapse_whitespace::CollapseWhitespaceSanitizer;
21pub use self::lowercase::LowerCaseSanitizer;
22pub use self::null_if_empty::NullIfEmptySanitizer;
23pub use self::round_to_scale::RoundToScaleSanitizer;
24pub use self::slug_sanitizer::SlugSanitizer;
25pub use self::timezone::{TimezoneSanitizer, UtcSanitizer};
26pub use self::trim::TrimSanitizer;
27pub use self::uppercase::UpperCaseSanitizer;
28pub use self::url_encoding::UrlEncodingSanitizer;
29use crate::prelude::{IcDbmsResult, Value};
30
31/// Trait for sanitizing [`Value`]s.
32pub trait Sanitize {
33    /// Sanitizes the given [`Value`].
34    ///
35    /// In case of error it should return a [`crate::prelude::IcDbmsError::Sanitize`] error.
36    ///
37    /// Sanitizers should not return error if the value is not of the expected type, they should just return the value as is.
38    fn sanitize(&self, value: Value) -> IcDbmsResult<Value>;
39}