Skip to main content

StringSchema

Struct StringSchema 

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

Schema representing string constraints and mapping metadata.

Implementations§

Source§

impl StringSchema

Source

pub fn new() -> Self

Creates a new StringSchema with no validation constraints.

Source

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

Constrains the string to have a minimum character count of $N$.

Source

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

Constrains the string to have a maximum character count of $M$.

Source

pub fn non_empty(self) -> Self

Constrains the string to be non-empty.

Source

pub fn alphanumeric(self) -> Self

Constrains the string to contain only alphanumeric characters.

Source

pub fn email(self) -> Self

Restricts the string format to standard email addresses.

Source

pub fn url(self) -> Self

Restricts the string format to absolute URLs.

Source

pub fn regex(self, pattern: &str) -> Self

Matches the string value against a custom Rust regular expression pattern.

Source

pub fn default(self, val: &str) -> Self

Configures a fallback default value used when this field is missing.

Source

pub fn alias(self, name: &str) -> Self

Registers a field key rename mapping for parsing input payloads.

Source

pub fn required(self) -> Self

Configures the schema to strictly fail if the field is absent.

Source

pub fn optional(self) -> Self

Registers the field as optional (permits Null values).

Source

pub fn strict(self) -> Self

Opts into strict validation mode: non-string inputs cause immediate failure instead of coercion.

Source

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

Returns the registered key alias name if defined.

Trait Implementations§

Source§

impl Default for StringSchema

Source§

fn default() -> StringSchema

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

impl SchemaValidator for StringSchema

Source§

fn validate(&self, value: &Value, field: &str) -> Result<(), ValidationError>

Validates the given Value against the structural rules of this schema. Read more
Source§

fn is_required(&self) -> bool

Returns true if the field must be supplied and lacks a default value.
Source§

fn default_value(&self) -> Option<Value>

Yields the fallback Value if this optional/default field is omitted.
Source§

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

Static string representing the readable type name.

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> 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, 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.