Skip to main content

ZString

Struct ZString 

Source
pub struct ZString { /* private fields */ }
Available on crate feature utoipa-5 only.
Expand description

Schema for string validation. Created via vld::string().

§Example

use vld::prelude::*;

let schema = vld::string().min(3).max(20).email();

Implementations§

Source§

impl ZString

Source

pub fn email(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid email address.

Source

pub fn email_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid email address.

With a custom error message.

Source

pub fn url(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid URL (http/https).

Source

pub fn url_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid URL (http/https).

With a custom error message.

Source

pub fn uuid(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid UUID.

Source

pub fn uuid_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid UUID.

With a custom error message.

Source

pub fn ip(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid IP address (IPv4 or IPv6).

Source

pub fn ip_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid IP address (IPv4 or IPv6).

With a custom error message.

Source

pub fn slug(self) -> ZString

Available on crate feature poem-openapi only.

Must be a URL-friendly slug ([a-z0-9-]).

Source

pub fn slug_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a URL-friendly slug ([a-z0-9-]).

With a custom error message.

Source

pub fn color(self) -> ZString

Available on crate feature poem-openapi only.

Must be a color (#RRGGBB, #RRGGBBAA, rgb(...), hsl(...)).

Source

pub fn color_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a color (#RRGGBB, #RRGGBBAA, rgb(...), hsl(...)).

With a custom error message.

Source

pub fn currency_code(self) -> ZString

Available on crate feature poem-openapi only.

Must be an active ISO 4217 currency code with minor units (USD, JPY; uppercase; metals and test codes such as XAU, XTS and withdrawn codes such as HRK are rejected).

Source

pub fn currency_code_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an active ISO 4217 currency code with minor units (USD, JPY; uppercase; metals and test codes such as XAU, XTS and withdrawn codes such as HRK are rejected).

With a custom error message.

Source

pub fn country_code(self) -> ZString

Available on crate feature poem-openapi only.

Must be a country code (ISO-3166 alpha-2).

Source

pub fn country_code_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a country code (ISO-3166 alpha-2).

With a custom error message.

Source

pub fn locale(self) -> ZString

Available on crate feature poem-openapi only.

Must be a locale (ll or ll-RR, example: en, en-US).

Source

pub fn locale_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a locale (ll or ll-RR, example: en, en-US).

With a custom error message.

Source

pub fn cron(self) -> ZString

Available on crate feature poem-openapi only.

Must be a cron expression: 5 fields (6 with seconds first) of *, values, ranges, lists and /steps in range, month / weekday names, ? in the day fields; or @daily & co.

Source

pub fn cron_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a cron expression: 5 fields (6 with seconds first) of *, values, ranges, lists and /steps in range, month / weekday names, ? in the day fields; or @daily & co.

With a custom error message.

Source

pub fn ipv4(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid IPv4 address.

Source

pub fn ipv4_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid IPv4 address.

With a custom error message.

Source

pub fn ipv6(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid IPv6 address (IPv4-mapped forms included).

Source

pub fn ipv6_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid IPv6 address (IPv4-mapped forms included).

With a custom error message.

Source

pub fn cidr(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid CIDR block (IPv4/IPv6 with a decimal prefix).

Source

pub fn cidr_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid CIDR block (IPv4/IPv6 with a decimal prefix).

With a custom error message.

Source

pub fn mac(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid MAC address (xx:xx:xx:xx:xx:xx).

Source

pub fn mac_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid MAC address (xx:xx:xx:xx:xx:xx).

With a custom error message.

Source

pub fn hex(self) -> ZString

Available on crate feature poem-openapi only.

Must contain only hexadecimal characters.

Source

pub fn hex_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must contain only hexadecimal characters.

With a custom error message.

Source

pub fn credit_card(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid credit card number: digits with optional spaces/dashes, 12-19 digits, Luhn check.

Source

pub fn credit_card_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid credit card number: digits with optional spaces/dashes, 12-19 digits, Luhn check.

With a custom error message.

Source

pub fn phone(self) -> ZString

Available on crate feature poem-openapi only.

Must be an international phone number: leading +, 8-15 digits, optional spaces, dashes and parentheses.

Source

pub fn phone_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an international phone number: leading +, 8-15 digits, optional spaces, dashes and parentheses.

With a custom error message.

Source

pub fn semver(self) -> ZString

Available on crate feature poem-openapi only.

Must be a semantic version (MAJOR.MINOR.PATCH, optional v prefix).

Source

pub fn semver_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a semantic version (MAJOR.MINOR.PATCH, optional v prefix).

With a custom error message.

Source

pub fn jwt(self) -> ZString

Available on crate feature poem-openapi only.

Must be a JWT-like token (header.payload.signature, base64url parts).

Source

pub fn jwt_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a JWT-like token (header.payload.signature, base64url parts).

With a custom error message.

Source

pub fn ascii(self) -> ZString

Available on crate feature poem-openapi only.

Must contain only ASCII characters.

Source

pub fn ascii_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must contain only ASCII characters.

With a custom error message.

Source

pub fn alpha(self) -> ZString

Available on crate feature poem-openapi only.

Must contain only alphabetic ASCII characters.

Source

pub fn alpha_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must contain only alphabetic ASCII characters.

With a custom error message.

Source

pub fn alphanumeric(self) -> ZString

Available on crate feature poem-openapi only.

Must contain only ASCII alphanumeric characters.

Source

pub fn alphanumeric_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must contain only ASCII alphanumeric characters.

With a custom error message.

Source

pub fn lowercase(self) -> ZString

Available on crate feature poem-openapi only.

Must already be lowercase.

Source

pub fn lowercase_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must already be lowercase.

With a custom error message.

Source

pub fn uppercase(self) -> ZString

Available on crate feature poem-openapi only.

Must already be uppercase.

Source

pub fn uppercase_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must already be uppercase.

With a custom error message.

Source

pub fn base64(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid (padded) Base64 string.

Source

pub fn base64_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid (padded) Base64 string.

With a custom error message.

Source

pub fn base64url(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid Base64URL string (-/_ alphabet, padding optional).

Source

pub fn base64url_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid Base64URL string (-/_ alphabet, padding optional).

With a custom error message.

Source

pub fn json(self) -> ZString

Available on crate feature poem-openapi only.

Must be a string containing one valid JSON document.

Source

pub fn json_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a string containing one valid JSON document.

With a custom error message.

Source

pub fn iso_date(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ISO 8601 calendar date (YYYY-MM-DD, real day of month).

Source

pub fn iso_date_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ISO 8601 calendar date (YYYY-MM-DD, real day of month).

With a custom error message.

Source

pub fn iso_datetime(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ISO 8601 datetime: YYYY-MM-DDTHH:MM:SS[.frac] (seconds required, T/t) with optional Z/z / ±HH:MM — the same grammar as vld::chrono::datetime() & co.

Source

pub fn iso_datetime_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ISO 8601 datetime: YYYY-MM-DDTHH:MM:SS[.frac] (seconds required, T/t) with optional Z/z / ±HH:MM — the same grammar as vld::chrono::datetime() & co.

With a custom error message.

Source

pub fn iso_time(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ISO 8601 time (HH:MM[:SS[.frac]]).

Source

pub fn iso_time_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ISO 8601 time (HH:MM[:SS[.frac]]).

With a custom error message.

Source

pub fn hostname(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid hostname.

Source

pub fn hostname_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid hostname.

With a custom error message.

Source

pub fn cuid2(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid CUID2 (2-32 lowercase alphanumerics, starting with a letter).

Source

pub fn cuid2_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid CUID2 (2-32 lowercase alphanumerics, starting with a letter).

With a custom error message.

Source

pub fn ulid(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ULID (26-char Crockford Base32).

Source

pub fn ulid_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid ULID (26-char Crockford Base32).

With a custom error message.

Source

pub fn nanoid(self) -> ZString

Available on crate feature poem-openapi only.

Must be a valid Nano ID (alphanumeric + _ + -).

Source

pub fn nanoid_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a valid Nano ID (alphanumeric + _ + -).

With a custom error message.

Source

pub fn emoji(self) -> ZString

Available on crate feature poem-openapi only.

Must be non-empty and consist only of emoji.

Source

pub fn emoji_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be non-empty and consist only of emoji.

With a custom error message.

Source

pub fn country(self) -> ZString

Available on crate feature poem-openapi only.

Must be an assigned ISO 3166-1 alpha-2 country code (US, DE; uppercase). country_code checks only the shape.

Source

pub fn country_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an assigned ISO 3166-1 alpha-2 country code (US, DE; uppercase). country_code checks only the shape.

With a custom error message.

Source

pub fn country_alpha3(self) -> ZString

Available on crate feature poem-openapi only.

Must be an assigned ISO 3166-1 alpha-3 country code (USA, DEU; uppercase).

Source

pub fn country_alpha3_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an assigned ISO 3166-1 alpha-3 country code (USA, DEU; uppercase).

With a custom error message.

Source

pub fn iban(self) -> ZString

Available on crate feature poem-openapi only.

Must be an IBAN: uppercase, optional single spaces between groups, the country’s registry length and a valid mod-97 checksum.

Source

pub fn iban_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an IBAN: uppercase, optional single spaces between groups, the country’s registry length and a valid mod-97 checksum.

With a custom error message.

Source

pub fn bic(self) -> ZString

Available on crate feature poem-openapi only.

Must be a BIC / SWIFT code (ISO 9362): 8 or 11 uppercase characters with an ISO 3166 country in positions 5-6.

Source

pub fn bic_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a BIC / SWIFT code (ISO 9362): 8 or 11 uppercase characters with an ISO 3166 country in positions 5-6.

With a custom error message.

Source

pub fn isbn(self) -> ZString

Available on crate feature poem-openapi only.

Must be an ISBN-10 or ISBN-13 with a valid check digit (single - / space separators allowed).

Source

pub fn isbn_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an ISBN-10 or ISBN-13 with a valid check digit (single - / space separators allowed).

With a custom error message.

Source

pub fn ean(self) -> ZString

Available on crate feature poem-openapi only.

Must be an EAN / GTIN: 8, 12, 13 or 14 digits with a valid GS1 check digit.

Source

pub fn ean_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an EAN / GTIN: 8, 12, 13 or 14 digits with a valid GS1 check digit.

With a custom error message.

Source

pub fn vin(self) -> ZString

Available on crate feature poem-openapi only.

Must be a 17-character VIN (ISO 3779, no I / O / Q) with the North American check digit (49 CFR 565) in position 9. European VINs often carry no check digit: use a pattern for those.

Source

pub fn vin_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a 17-character VIN (ISO 3779, no I / O / Q) with the North American check digit (49 CFR 565) in position 9. European VINs often carry no check digit: use a pattern for those.

With a custom error message.

Source

pub fn timezone(self) -> ZString

Available on crate feature poem-openapi only.

Must be an IANA time zone name (Europe/Berlin, UTC). With the jiff feature the name must exist in jiff’s time zone database; without it only the shape is checked.

Source

pub fn timezone_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be an IANA time zone name (Europe/Berlin, UTC). With the jiff feature the name must exist in jiff’s time zone database; without it only the shape is checked.

With a custom error message.

Source

pub fn mime(self) -> ZString

Available on crate feature poem-openapi only.

Must be a media type: type/subtype[+suffix] with optional ; name=value parameters.

Source

pub fn mime_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a media type: type/subtype[+suffix] with optional ; name=value parameters.

With a custom error message.

Source

pub fn object_id(self) -> ZString

Available on crate feature poem-openapi only.

Must be a MongoDB ObjectId (24 hex digits).

Source

pub fn object_id_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must be a MongoDB ObjectId (24 hex digits).

With a custom error message.

Source§

impl ZString

Source

pub fn new() -> ZString

Available on crate feature poem-openapi only.

Create the schema (the same as its vld:: constructor function).

Source

pub fn type_error(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Set a custom error message for type mismatch (when the input is not a string).

§Example
use vld::prelude::*;
let schema = vld::string().type_error("Must be text!");
let err = schema.parse("42").unwrap_err();
assert!(err.issues[0].message.contains("Must be text!"));
Source

pub fn with_messages<F>(self, f: F) -> ZString
where F: Fn(&str) -> Option<String> + Send + Sync + 'static,

Available on crate feature poem-openapi only.

Override error messages in bulk by check key.

The closure receives the check key (e.g. "too_small", "invalid_email") and should return Some(new_message) to replace, or None to keep the original.

Keys: "too_small", "too_big", "invalid_length", "non_empty", "invalid_regex", "invalid_starts_with", "invalid_ends_with", "invalid_contains", and "invalid_<format>" for every format check ("invalid_email", "invalid_url", "invalid_uuid", "invalid_ip", "invalid_currency", "invalid_phone_e164", …).

The closure is consulted when an issue is built, so it covers checks added before and after this call; a per-check message (*_msg(...)) takes precedence over it. A later call replaces it.

§Example
use vld::prelude::*;
let schema = vld::string().min(3).email()
    .with_messages(|key| match key {
        "too_small" => Some("Too short!".into()),
        "invalid_email" => Some("Bad email!".into()),
        _ => None,
    });
Source

pub fn min(self, len: usize) -> ZString

Available on crate feature poem-openapi only.

Minimum string length in characters (inclusive).

Source

pub fn min_bytes(self, n: usize) -> ZString

Available on crate feature poem-openapi only.

Minimum UTF-8 length in bytes (too_small, origin bytes): for byte-limited storage. min counts characters.

Source

pub fn max_bytes(self, n: usize) -> ZString

Available on crate feature poem-openapi only.

Maximum UTF-8 length in bytes (too_big, origin bytes). Not expressible in JSON Schema (maxLength counts characters), so it is left out of it.

use vld::prelude::*;
let name = vld::string().max_bytes(4);
assert!(name.parse(r#""abcd""#).is_ok());
assert!(name.parse(r#""абв""#).is_err()); // 3 characters, 6 bytes
Source

pub fn min_msg(self, len: usize, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Minimum string length with custom message.

Source

pub fn max(self, len: usize) -> ZString

Available on crate feature poem-openapi only.

Maximum string length in characters (inclusive).

Source

pub fn max_msg(self, len: usize, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Maximum string length with custom message.

Source

pub fn len(self, len: usize) -> ZString

Available on crate feature poem-openapi only.

Exact string length in characters.

Source

pub fn len_msg(self, len: usize, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Exact string length with custom message.

Source

pub fn rule(self, rule: impl Rule<str>) -> ZString

Available on crate feature poem-openapi only.

Check with a reusable Rule on the string (keeps the ZString builder; see vld::rules).

Source

pub fn rule_msg(self, rule: impl Rule<str>, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

rule with a custom message.

Source

pub fn starts_with(self, prefix: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must start with the given prefix.

Source

pub fn starts_with_msg( self, prefix: impl Into<String>, msg: impl Into<String>, ) -> ZString

Available on crate feature poem-openapi only.

Must start with the given prefix, with custom message.

Source

pub fn ends_with(self, suffix: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must end with the given suffix.

Source

pub fn ends_with_msg( self, suffix: impl Into<String>, msg: impl Into<String>, ) -> ZString

Available on crate feature poem-openapi only.

Must end with the given suffix, with custom message.

Source

pub fn contains(self, sub: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must contain the given substring.

Source

pub fn contains_msg( self, sub: impl Into<String>, msg: impl Into<String>, ) -> ZString

Available on crate feature poem-openapi only.

Must contain the given substring, with custom message.

Source

pub fn non_empty(self) -> ZString

Available on crate feature poem-openapi only.

Must not be empty.

Source

pub fn non_empty_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

Must not be empty, with custom message.

Source

pub fn trim(self) -> ZString

Available on crate feature poem-openapi only.

Trim whitespace before validation.

Source

pub fn to_lowercase(self) -> ZString

Available on crate feature poem-openapi only.

Convert to lowercase before validation.

Source

pub fn truncate(self, n: usize) -> ZString

Available on crate feature poem-openapi only.

Keep at most the first n characters (before the checks, in the order transforms were added): for storage limits that cut instead of rejecting.

use vld::prelude::*;
let title = vld::string().trim().truncate(5);
assert_eq!(title.parse(r#"" Hello, world ""#).unwrap(), "Hello");
Source

pub fn to_uppercase(self) -> ZString

Available on crate feature poem-openapi only.

Convert to uppercase before validation.

Source

pub fn require_lowercase(self) -> ZString

Available on crate feature poem-openapi only.

Password rule: at least one lowercase letter (Unicode Lowercase).

Every password rule reports its own issue (invalid_string / password_lowercase, password_uppercase, password_digit, password_symbol, password_repeat, password_strength), so a form can list every unmet rule. Combine with min and redact so the password never appears in errors:

use vld::prelude::*;
let password = vld::string()
    .min(12)
    .require_lowercase()
    .require_uppercase()
    .require_digit()
    .require_symbol()
    .max_repeat(2)
    .redact();
let err = password.parse(r#""aaapassword""#).unwrap_err();
let keys: Vec<_> = err.issues.iter().map(|i| i.code.message_keys()[0].clone()).collect();
assert_eq!(keys, [
    "too_small.string",
    "invalid_string.password_uppercase",
    "invalid_string.password_digit",
    "invalid_string.password_symbol",
    "invalid_string.password_repeat",
]);
assert!(!err.to_string().contains("aaapassword"));
Source

pub fn require_lowercase_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

require_lowercase with a custom message.

Source

pub fn require_uppercase(self) -> ZString

Available on crate feature poem-openapi only.

Password rule: at least one uppercase letter (Unicode Uppercase).

Source

pub fn require_uppercase_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

require_uppercase with a custom message.

Source

pub fn require_digit(self) -> ZString

Available on crate feature poem-openapi only.

Password rule: at least one ASCII digit.

Source

pub fn require_digit_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

require_digit with a custom message.

Source

pub fn require_symbol(self) -> ZString

Available on crate feature poem-openapi only.

Password rule: at least one symbol — a character that is neither alphanumeric nor whitespace (!, _, €, …).

Source

pub fn require_symbol_msg(self, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

require_symbol with a custom message.

Source

pub fn max_repeat(self, n: usize) -> ZString

Available on crate feature poem-openapi only.

Password rule: no character repeated more than n times in a row (max_repeat(2) rejects aaa).

Source

pub fn max_repeat_msg(self, n: usize, msg: impl Into<String>) -> ZString

Available on crate feature poem-openapi only.

max_repeat with a custom message.

Source

pub fn coerce(self) -> ZString

Available on crate feature poem-openapi only.

Coerce non-string values (numbers, booleans) to string.

Source

pub fn coerce_bools( self, on: impl Into<String>, off: impl Into<String>, ) -> ZString

Available on crate feature poem-openapi only.

Coerce like coerce, writing booleans as on / off instead of "true" / "false" (legacy stores often keep "1" / "0").

use vld::prelude::*;
let flag = vld::string().coerce_bools("1", "0");
assert_eq!(flag.parse("true").unwrap(), "1");
assert_eq!(flag.parse("false").unwrap(), "0");
assert_eq!(flag.parse("7").unwrap(), "7");

Trait Implementations§

Source§

impl Clone for ZString

Source§

fn clone(&self) -> ZString

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl CollectNestedSchemas for ZString

Available on crate feature openapi only.
Source§

fn collect_nested_schemas(&self, _out: &mut Vec<(&'static str, fn() -> Value)>)

Add the named schemas this schema references to _out (for components.schemas).
Source§

impl Default for ZString

Source§

fn default() -> ZString

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

impl JsonSchema for ZString

Available on crate feature openapi only.

Generate a JSON Schema representation of this string schema.

  • Length bounds: the strictest min/max/len/non_empty wins.
  • Formats: the first goes into format, further ones into allOf.
  • pattern/starts_with/ends_with/contains become patterns (first in pattern, further ones in allOf).
  • Password rules add format: "password" and an x-password object (lowercase, uppercase, digit, symbol: true; maxRepeat, minScore: numbers).
Source§

fn json_schema(&self) -> Value

Generate a JSON Schema representation.
Source§

fn is_required(&self) -> bool

Whether this schema should be included in an object’s required array. Read more
Source§

impl VldSchema for ZString

Source§

type Output = String

The Rust type produced by this schema after successful parsing.
Source§

fn parse_value(&self, value: &Value) -> Result<String, VldError>

Parse and validate a serde_json::Value.
Source§

fn parse_missing(&self) -> Result<Self::Output, VldError>

Parse an object field whose key is absent. Read more
Source§

fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
where I: VldInput + ?Sized,

Parse from any supported input (JSON string, file path, serde_json::Value, etc.)
Source§

fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>
where T: Serialize,

Validate an existing Rust value against this schema. Read more
Source§

fn is_valid<T>(&self, value: &T) -> bool
where T: Serialize,

Check if an existing Rust value passes this schema’s validation. Read more
Source§

fn optional(self) -> ZOptional<Self>

Make this field optional. Missing or null values become None.
Source§

fn nullable(self) -> ZNullable<Self>

Allow null values. Null becomes None.
Source§

fn with_default(self, value: Self::Output) -> ZDefault<Self>
where Self::Output: Clone,

Provide a default value when the field is missing or null.
Source§

fn blank_as(self, value: Self::Output) -> ZDefault<Self>
where Self::Output: Clone,

Like with_default, and a blank string (empty or whitespace only) also becomes value: legacy stores that write "" or null for “unset”. Read more
Source§

fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
where F: Fn(&Self::Output) -> bool,

Add a custom refinement check without changing the output type.
Source§

fn rule<R>(self, rule: R) -> ZRule<Self, R>
where Self: Sized, R: Rule<Self::Output>,

Check the output with a reusable Rule (output type unchanged). Read more
Source§

fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
where Self: Sized, R: Rule<Self::Output>,

rule with a custom error message.
Source§

fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
where F: Fn(Self::Output) -> Result<U, E>, E: Display,

Transform the output with a fallible function; an Err becomes a validation issue (Custom { code: "transform" }, message = the error). Read more
Source§

fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
where F: Fn(Self::Output) -> U,

Transform the output value after successful parsing.
Source§

fn nullish(self) -> ZNullish<Self>

Make this field nullish (both optional and nullable).
Source§

fn catch(self, fallback: Self::Output) -> ZCatch<Self>
where Self::Output: Clone,

Return a fallback value on ANY validation error.
Source§

fn pipe<S>(self, next: S) -> ZPipe<Self, S>
where S: VldSchema, Self::Output: Serialize,

Chain this schema’s output into another schema. Read more
Source§

fn describe(self, description: &str) -> ZDescribe<Self>

Attach a human-readable description/label to this schema. Read more
Source§

fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
where F: Fn(&Self::Output, &mut VldError),

Add a custom refinement that can produce multiple errors. Read more
Source§

fn or<B>(self, other: B) -> ZUnion2<Self, B>
where B: VldSchema,

Create a union: this schema or another. Returns Either<Self::Output, B::Output>.
Source§

fn and<B>(self, other: B) -> ZIntersection<Self, B>
where B: VldSchema,

Create an intersection: input must satisfy both schemas.
Source§

fn message(self, msg: impl Into<String>) -> ZMessage<Self>

Override the error message for this schema. Read more
Source§

fn redact(self) -> ZRedact<Self>

Keep the input out of this schema’s errors: every issue (nested ones included) gets received: "[redacted]"; paths, codes and messages stay. For passwords, tokens and personal data — see ZRedact. Read more

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> DynSchema for T

Source§

fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>

Parse value and return the output serialized back to JSON.
Source§

fn dyn_parse_missing(&self) -> Result<Value, VldError>

VldSchema::parse_missing of the erased schema.
Source§

fn dyn_json_schema(&self) -> Value

Available on crate feature openapi only.
JSON Schema of the erased schema.
Source§

fn dyn_is_required(&self) -> bool

Available on crate feature openapi only.
Whether this field belongs in an object’s JSON Schema required array.
Source§

fn dyn_collect_nested_schemas( &self, out: &mut Vec<(&'static str, fn() -> Value)>, )

Available on crate feature openapi only.
Collect named nested schemas (OpenAPI components) referenced by this schema.
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> Schema for T

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 = !

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

fn try_from(value: U) -> Result<T, !>

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