Check

Struct Check 

Source
pub struct Check { /* private fields */ }
Expand description

A validation check containing one or more constraints.

A Check groups related constraints together and assigns them a severity level. Checks are the building blocks of validation suites. When a check runs, all its constraints are evaluated, and the check fails if any constraint fails.

§Examples

§Basic Check

use term_guard::core::{Check, Level};

let check = Check::builder("user_data_quality")
    .level(Level::Error)
    .description("Validates user data quality")
    .build();

§Check with Constraints

use term_guard::core::{Check, Level, ConstraintOptions};
use term_guard::constraints::{Assertion, UniquenessType, StatisticType, FormatType, FormatOptions};

let check = Check::builder("customer_validation")
    .level(Level::Error)
    .description("Ensure customer data integrity")
    // Completeness checks using unified API
    .completeness("customer_id", ConstraintOptions::new().with_threshold(1.0))
    .completeness("email", ConstraintOptions::new().with_threshold(0.99))
    // Uniqueness checks using unified API
    .validates_uniqueness(vec!["customer_id"], 1.0)
    .validates_uniqueness(vec!["email", "region"], 1.0)
    // Pattern validation using format
    .has_format("phone", FormatType::Regex(r"^\+?\d{3}-\d{3}-\d{4}$".to_string()), 0.95, FormatOptions::default())
    // Range checks using statistic
    .statistic("age", StatisticType::Min, Assertion::GreaterThanOrEqual(18.0))
    .statistic("age", StatisticType::Max, Assertion::LessThanOrEqual(120.0))
    .build();

§Data Quality Check

use term_guard::core::{Check, Level};
use term_guard::constraints::{Assertion, StatisticType};

let check = Check::builder("data_types_and_formats")
    .level(Level::Warning)
    // Ensure consistent data types using the unified API
    .has_consistent_data_type("order_date", 0.99)
    .has_consistent_data_type("product_id", 0.95)
    // String length validation
    .has_min_length("password", 8)
    .has_max_length("username", 20)
    // Check for PII
    .validates_credit_card("comments", 0.0, true)  // Should be 0%
    .validates_email("email_field", 0.98)
    // Statistical checks
    .statistic("order_value", StatisticType::Mean, Assertion::Between(50.0, 500.0))
    .statistic("response_time", StatisticType::StandardDeviation, Assertion::LessThan(100.0))
    .build();

§Enhanced Format Validation

use term_guard::core::{Check, Level};
use term_guard::constraints::FormatOptions;

let check = Check::builder("enhanced_format_validation")
    .level(Level::Error)
    // Basic format validation
    .validates_email("email", 0.95)
    .validates_url("website", 0.90, false)
    .validates_phone("phone", 0.85, Some("US"))
    // Enhanced format validation with options
    .validates_email_with_options(
        "secondary_email",
        0.80,
        FormatOptions::lenient()  // Case insensitive, trimming, nulls allowed
    )
    .validates_url_with_options(
        "dev_url",
        0.75,
        true, // allow localhost
        FormatOptions::case_insensitive().trim_before_check(true)
    )
    .validates_regex_with_options(
        "product_code",
        r"^[A-Z]{2}\d{4}$",
        0.98,
        FormatOptions::strict()  // Case sensitive, no nulls, no trimming
    )
    .build();

Implementations§

Source§

impl Check

Source

pub fn builder(name: impl Into<String>) -> CheckBuilder

Creates a new builder for constructing a check.

§Arguments
  • name - The name of the check
§Examples
use term_guard::core::Check;

let builder = Check::builder("data_quality");
Source

pub fn name(&self) -> &str

Returns the name of the check.

Source

pub fn level(&self) -> Level

Returns the severity level of the check.

Source

pub fn description(&self) -> Option<&str>

Returns the description of the check if available.

Source

pub fn constraints(&self) -> &[Arc<dyn Constraint>]

Returns the constraints in this check.

Trait Implementations§

Source§

impl CheckMultiTableExt for Check

Source§

fn multi_table(name: impl Into<String>) -> MultiTableCheck

Create a multi-table validation check.
Source§

impl Clone for Check

Source§

fn clone(&self) -> Check

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Check

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Check

§

impl !RefUnwindSafe for Check

§

impl Send for Check

§

impl Sync for Check

§

impl Unpin for Check

§

impl !UnwindSafe for Check

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,