pub struct Checks { /* private fields */ }Expand description
Fluent builder for heuristic validation checks.
This builder accumulates checks and implements Validate to score
text based on how many checks pass. Weights determine the contribution
of each check to the final score.
§Stack Allocation
Checks are stored in a SmallVec with inline capacity for common cases, avoiding heap allocation for typical usage patterns.
Implementations§
Source§impl Checks
impl Checks
Sourcepub fn require(self, pattern: impl Into<String>) -> Self
pub fn require(self, pattern: impl Into<String>) -> Self
Require a substring pattern to be present.
The check fails if the text does not contain the pattern.
Sourcepub fn require_weighted(self, pattern: impl Into<String>, weight: f64) -> Self
pub fn require_weighted(self, pattern: impl Into<String>, weight: f64) -> Self
Require a substring pattern with custom weight.
Sourcepub fn require_all<I, S>(self, patterns: I) -> Self
pub fn require_all<I, S>(self, patterns: I) -> Self
Require multiple substring patterns to be present.
Equivalent to calling .require() for each pattern.
Sourcepub fn require_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
pub fn require_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
Require multiple substring patterns with custom weight.
Sourcepub fn forbid(self, pattern: impl Into<String>) -> Self
pub fn forbid(self, pattern: impl Into<String>) -> Self
Forbid a substring pattern.
The check fails if the text contains the pattern.
Sourcepub fn forbid_weighted(self, pattern: impl Into<String>, weight: f64) -> Self
pub fn forbid_weighted(self, pattern: impl Into<String>, weight: f64) -> Self
Forbid a substring pattern with custom weight.
Sourcepub fn forbid_all<I, S>(self, patterns: I) -> Self
pub fn forbid_all<I, S>(self, patterns: I) -> Self
Forbid multiple substring patterns.
Equivalent to calling .forbid() for each pattern.
Sourcepub fn forbid_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
pub fn forbid_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
Forbid multiple substring patterns with custom weight.
Sourcepub fn regex(self, pattern: impl Into<String>) -> Self
pub fn regex(self, pattern: impl Into<String>) -> Self
Require a regex pattern to match.
The regex is lazily compiled on first use.
Sourcepub fn regex_weighted(self, pattern: impl Into<String>, weight: f64) -> Self
pub fn regex_weighted(self, pattern: impl Into<String>, weight: f64) -> Self
Require a regex pattern with custom weight.
Sourcepub fn regex_all<I, S>(self, patterns: I) -> Self
pub fn regex_all<I, S>(self, patterns: I) -> Self
Require multiple regex patterns to match.
Equivalent to calling .regex() for each pattern.
Sourcepub fn regex_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
pub fn regex_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
Require multiple regex patterns with custom weight.
Sourcepub fn min_len_weighted(self, n: usize, weight: f64) -> Self
pub fn min_len_weighted(self, n: usize, weight: f64) -> Self
Require minimum text length with custom weight.
Sourcepub fn max_len_weighted(self, n: usize, weight: f64) -> Self
pub fn max_len_weighted(self, n: usize, weight: f64) -> Self
Require maximum text length with custom weight.
Sourcepub fn max_errors(self, n: usize) -> Self
pub fn max_errors(self, n: usize) -> Self
Limit the number of error-like lines.
Counts lines containing “error”, “Error”, or “ERROR”.
Sourcepub fn pred(self, name: &'static str, f: fn(&str) -> bool) -> Self
pub fn pred(self, name: &'static str, f: fn(&str) -> bool) -> Self
Add a custom predicate check.
The predicate receives the text and returns true if it passes.
Sourcepub fn pred_weighted(
self,
name: &'static str,
f: fn(&str) -> bool,
weight: f64,
) -> Self
pub fn pred_weighted( self, name: &'static str, f: fn(&str) -> bool, weight: f64, ) -> Self
Add a custom predicate check with custom weight.
Sourcepub fn feedback(self, msg: impl Into<String>) -> Self
pub fn feedback(self, msg: impl Into<String>) -> Self
Set custom feedback for the most recently added check.
Sourcepub fn require_if(self, cond: bool, pattern: impl Into<String>) -> Self
pub fn require_if(self, cond: bool, pattern: impl Into<String>) -> Self
Conditionally require a substring pattern.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Checks
impl RefUnwindSafe for Checks
impl Send for Checks
impl Sync for Checks
impl Unpin for Checks
impl UnsafeUnpin for Checks
impl UnwindSafe for Checks
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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