Skip to main content

Checks

Struct Checks 

Source
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

Source

pub fn new() -> Self

Create a new empty checks builder.

Source

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.

Source

pub fn require_weighted(self, pattern: impl Into<String>, weight: f64) -> Self

Require a substring pattern with custom weight.

Source

pub fn require_all<I, S>(self, patterns: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Require multiple substring patterns to be present.

Equivalent to calling .require() for each pattern.

Source

pub fn require_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Require multiple substring patterns with custom weight.

Source

pub fn forbid(self, pattern: impl Into<String>) -> Self

Forbid a substring pattern.

The check fails if the text contains the pattern.

Source

pub fn forbid_weighted(self, pattern: impl Into<String>, weight: f64) -> Self

Forbid a substring pattern with custom weight.

Source

pub fn forbid_all<I, S>(self, patterns: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Forbid multiple substring patterns.

Equivalent to calling .forbid() for each pattern.

Source

pub fn forbid_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Forbid multiple substring patterns with custom weight.

Source

pub fn regex(self, pattern: impl Into<String>) -> Self

Require a regex pattern to match.

The regex is lazily compiled on first use.

Source

pub fn regex_weighted(self, pattern: impl Into<String>, weight: f64) -> Self

Require a regex pattern with custom weight.

Source

pub fn regex_all<I, S>(self, patterns: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Require multiple regex patterns to match.

Equivalent to calling .regex() for each pattern.

Source

pub fn regex_all_weighted<I, S>(self, patterns: I, weight: f64) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Require multiple regex patterns with custom weight.

Source

pub fn min_len(self, n: usize) -> Self

Require minimum text length.

Source

pub fn min_len_weighted(self, n: usize, weight: f64) -> Self

Require minimum text length with custom weight.

Source

pub fn max_len(self, n: usize) -> Self

Require maximum text length.

Source

pub fn max_len_weighted(self, n: usize, weight: f64) -> Self

Require maximum text length with custom weight.

Source

pub fn max_errors(self, n: usize) -> Self

Limit the number of error-like lines.

Counts lines containing “error”, “Error”, or “ERROR”.

Source

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.

Source

pub fn pred_weighted( self, name: &'static str, f: fn(&str) -> bool, weight: f64, ) -> Self

Add a custom predicate check with custom weight.

Source

pub fn weight(self, w: f64) -> Self

Set the weight for the most recently added check.

§Panics

Panics if no checks have been added yet.

Source

pub fn feedback(self, msg: impl Into<String>) -> Self

Set custom feedback for the most recently added check.

Source

pub fn require_if(self, cond: bool, pattern: impl Into<String>) -> Self

Conditionally require a substring pattern.

Source

pub fn forbid_if(self, cond: bool, pattern: impl Into<String>) -> Self

Conditionally forbid a substring pattern.

Source

pub fn python(self) -> Self

Preset checks for Python code.

Source

pub fn rust(self) -> Self

Preset checks for Rust code.

Source

pub fn json(self) -> Self

Preset checks for valid JSON.

Source

pub fn yaml(self) -> Self

Preset checks for YAML structure.

Source

pub fn sql(self) -> Self

Preset checks for SQL statements.

Trait Implementations§

Source§

impl Clone for Checks

Source§

fn clone(&self) -> Checks

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 Default for Checks

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Validate for Checks

Source§

fn validate(&self, text: &str) -> Score<'static>

Validate the given text and return a score. Read more
Source§

fn name(&self) -> &'static str

Get the name of this validator (for logging/debugging).

Auto Trait Implementations§

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, 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ValidateExt for V
where V: Validate,

Source§

fn and<V: Validate>(self, other: V) -> And<Self, V>

Combine with another validator using AND semantics. Read more
Source§

fn or<V: Validate>(self, other: V) -> Or<Self, V>

Combine with another validator using OR semantics. Read more
Source§

fn not(self) -> Not<Self>

Negate this validator.
Source§

fn weighted(self, w: f64) -> Weighted<Self>

Weight this validator’s score by a multiplier.