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
impl Check
Sourcepub fn builder(name: impl Into<String>) -> CheckBuilder
pub fn builder(name: impl Into<String>) -> CheckBuilder
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Returns the description of the check if available.
Sourcepub fn constraints(&self) -> &[Arc<dyn Constraint>]
pub fn constraints(&self) -> &[Arc<dyn Constraint>]
Returns the constraints in this check.
Trait Implementations§
Source§impl CheckMultiTableExt for Check
impl CheckMultiTableExt for Check
Source§fn multi_table(name: impl Into<String>) -> MultiTableCheck
fn multi_table(name: impl Into<String>) -> MultiTableCheck
Create a multi-table validation check.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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