pub struct ZString { /* private fields */ }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
impl ZString
Sourcepub fn email(self) -> ZString
Available on crate feature poem-openapi only.
pub fn email(self) -> ZString
poem-openapi only.Must be a valid email address.
Sourcepub fn email_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn email_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid email address.
With a custom error message.
Sourcepub fn url(self) -> ZString
Available on crate feature poem-openapi only.
pub fn url(self) -> ZString
poem-openapi only.Must be a valid URL (http/https).
Sourcepub fn url_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn url_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid URL (http/https).
With a custom error message.
Sourcepub fn uuid(self) -> ZString
Available on crate feature poem-openapi only.
pub fn uuid(self) -> ZString
poem-openapi only.Must be a valid UUID.
Sourcepub fn uuid_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn uuid_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid UUID.
With a custom error message.
Sourcepub fn ip(self) -> ZString
Available on crate feature poem-openapi only.
pub fn ip(self) -> ZString
poem-openapi only.Must be a valid IP address (IPv4 or IPv6).
Sourcepub fn ip_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ip_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid IP address (IPv4 or IPv6).
With a custom error message.
Sourcepub fn slug(self) -> ZString
Available on crate feature poem-openapi only.
pub fn slug(self) -> ZString
poem-openapi only.Must be a URL-friendly slug ([a-z0-9-]).
Sourcepub fn slug_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn slug_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a URL-friendly slug ([a-z0-9-]).
With a custom error message.
Sourcepub fn color(self) -> ZString
Available on crate feature poem-openapi only.
pub fn color(self) -> ZString
poem-openapi only.Must be a color (#RRGGBB, #RRGGBBAA, rgb(...), hsl(...)).
Sourcepub fn color_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn color_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a color (#RRGGBB, #RRGGBBAA, rgb(...), hsl(...)).
With a custom error message.
Sourcepub fn currency_code(self) -> ZString
Available on crate feature poem-openapi only.
pub fn currency_code(self) -> ZString
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).
Sourcepub fn currency_code_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn currency_code_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn country_code(self) -> ZString
Available on crate feature poem-openapi only.
pub fn country_code(self) -> ZString
poem-openapi only.Must be a country code (ISO-3166 alpha-2).
Sourcepub fn country_code_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn country_code_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a country code (ISO-3166 alpha-2).
With a custom error message.
Sourcepub fn locale(self) -> ZString
Available on crate feature poem-openapi only.
pub fn locale(self) -> ZString
poem-openapi only.Must be a locale (ll or ll-RR, example: en, en-US).
Sourcepub fn locale_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn locale_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a locale (ll or ll-RR, example: en, en-US).
With a custom error message.
Sourcepub fn cron(self) -> ZString
Available on crate feature poem-openapi only.
pub fn cron(self) -> ZString
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.
Sourcepub fn cron_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn cron_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn ipv4(self) -> ZString
Available on crate feature poem-openapi only.
pub fn ipv4(self) -> ZString
poem-openapi only.Must be a valid IPv4 address.
Sourcepub fn ipv4_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ipv4_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid IPv4 address.
With a custom error message.
Sourcepub fn ipv6(self) -> ZString
Available on crate feature poem-openapi only.
pub fn ipv6(self) -> ZString
poem-openapi only.Must be a valid IPv6 address (IPv4-mapped forms included).
Sourcepub fn ipv6_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ipv6_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid IPv6 address (IPv4-mapped forms included).
With a custom error message.
Sourcepub fn cidr(self) -> ZString
Available on crate feature poem-openapi only.
pub fn cidr(self) -> ZString
poem-openapi only.Must be a valid CIDR block (IPv4/IPv6 with a decimal prefix).
Sourcepub fn cidr_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn cidr_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid CIDR block (IPv4/IPv6 with a decimal prefix).
With a custom error message.
Sourcepub fn mac(self) -> ZString
Available on crate feature poem-openapi only.
pub fn mac(self) -> ZString
poem-openapi only.Must be a valid MAC address (xx:xx:xx:xx:xx:xx).
Sourcepub fn mac_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn mac_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid MAC address (xx:xx:xx:xx:xx:xx).
With a custom error message.
Sourcepub fn hex(self) -> ZString
Available on crate feature poem-openapi only.
pub fn hex(self) -> ZString
poem-openapi only.Must contain only hexadecimal characters.
Sourcepub fn hex_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn hex_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must contain only hexadecimal characters.
With a custom error message.
Sourcepub fn credit_card(self) -> ZString
Available on crate feature poem-openapi only.
pub fn credit_card(self) -> ZString
poem-openapi only.Must be a valid credit card number: digits with optional spaces/dashes, 12-19 digits, Luhn check.
Sourcepub fn credit_card_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn credit_card_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn phone(self) -> ZString
Available on crate feature poem-openapi only.
pub fn phone(self) -> ZString
poem-openapi only.Must be an international phone number: leading +, 8-15 digits, optional spaces, dashes and parentheses.
Sourcepub fn phone_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn phone_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be an international phone number: leading +, 8-15 digits, optional spaces, dashes and parentheses.
With a custom error message.
Sourcepub fn semver(self) -> ZString
Available on crate feature poem-openapi only.
pub fn semver(self) -> ZString
poem-openapi only.Must be a semantic version (MAJOR.MINOR.PATCH, optional v prefix).
Sourcepub fn semver_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn semver_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a semantic version (MAJOR.MINOR.PATCH, optional v prefix).
With a custom error message.
Sourcepub fn jwt(self) -> ZString
Available on crate feature poem-openapi only.
pub fn jwt(self) -> ZString
poem-openapi only.Must be a JWT-like token (header.payload.signature, base64url parts).
Sourcepub fn jwt_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn jwt_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a JWT-like token (header.payload.signature, base64url parts).
With a custom error message.
Sourcepub fn ascii(self) -> ZString
Available on crate feature poem-openapi only.
pub fn ascii(self) -> ZString
poem-openapi only.Must contain only ASCII characters.
Sourcepub fn ascii_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ascii_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must contain only ASCII characters.
With a custom error message.
Sourcepub fn alpha(self) -> ZString
Available on crate feature poem-openapi only.
pub fn alpha(self) -> ZString
poem-openapi only.Must contain only alphabetic ASCII characters.
Sourcepub fn alpha_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn alpha_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must contain only alphabetic ASCII characters.
With a custom error message.
Sourcepub fn alphanumeric(self) -> ZString
Available on crate feature poem-openapi only.
pub fn alphanumeric(self) -> ZString
poem-openapi only.Must contain only ASCII alphanumeric characters.
Sourcepub fn alphanumeric_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn alphanumeric_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must contain only ASCII alphanumeric characters.
With a custom error message.
Sourcepub fn lowercase(self) -> ZString
Available on crate feature poem-openapi only.
pub fn lowercase(self) -> ZString
poem-openapi only.Must already be lowercase.
Sourcepub fn lowercase_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn lowercase_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must already be lowercase.
With a custom error message.
Sourcepub fn uppercase(self) -> ZString
Available on crate feature poem-openapi only.
pub fn uppercase(self) -> ZString
poem-openapi only.Must already be uppercase.
Sourcepub fn uppercase_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn uppercase_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must already be uppercase.
With a custom error message.
Sourcepub fn base64(self) -> ZString
Available on crate feature poem-openapi only.
pub fn base64(self) -> ZString
poem-openapi only.Must be a valid (padded) Base64 string.
Sourcepub fn base64_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn base64_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid (padded) Base64 string.
With a custom error message.
Sourcepub fn base64url(self) -> ZString
Available on crate feature poem-openapi only.
pub fn base64url(self) -> ZString
poem-openapi only.Must be a valid Base64URL string (-/_ alphabet, padding optional).
Sourcepub fn base64url_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn base64url_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid Base64URL string (-/_ alphabet, padding optional).
With a custom error message.
Sourcepub fn json(self) -> ZString
Available on crate feature poem-openapi only.
pub fn json(self) -> ZString
poem-openapi only.Must be a string containing one valid JSON document.
Sourcepub fn json_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn json_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a string containing one valid JSON document.
With a custom error message.
Sourcepub fn iso_date(self) -> ZString
Available on crate feature poem-openapi only.
pub fn iso_date(self) -> ZString
poem-openapi only.Must be a valid ISO 8601 calendar date (YYYY-MM-DD, real day of month).
Sourcepub fn iso_date_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn iso_date_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid ISO 8601 calendar date (YYYY-MM-DD, real day of month).
With a custom error message.
Sourcepub fn iso_datetime(self) -> ZString
Available on crate feature poem-openapi only.
pub fn iso_datetime(self) -> ZString
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.
Sourcepub fn iso_datetime_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn iso_datetime_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn iso_time(self) -> ZString
Available on crate feature poem-openapi only.
pub fn iso_time(self) -> ZString
poem-openapi only.Must be a valid ISO 8601 time (HH:MM[:SS[.frac]]).
Sourcepub fn iso_time_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn iso_time_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid ISO 8601 time (HH:MM[:SS[.frac]]).
With a custom error message.
Sourcepub fn hostname(self) -> ZString
Available on crate feature poem-openapi only.
pub fn hostname(self) -> ZString
poem-openapi only.Must be a valid hostname.
Sourcepub fn hostname_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn hostname_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid hostname.
With a custom error message.
Sourcepub fn cuid2(self) -> ZString
Available on crate feature poem-openapi only.
pub fn cuid2(self) -> ZString
poem-openapi only.Must be a valid CUID2 (2-32 lowercase alphanumerics, starting with a letter).
Sourcepub fn cuid2_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn cuid2_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid CUID2 (2-32 lowercase alphanumerics, starting with a letter).
With a custom error message.
Sourcepub fn ulid(self) -> ZString
Available on crate feature poem-openapi only.
pub fn ulid(self) -> ZString
poem-openapi only.Must be a valid ULID (26-char Crockford Base32).
Sourcepub fn ulid_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ulid_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid ULID (26-char Crockford Base32).
With a custom error message.
Sourcepub fn nanoid(self) -> ZString
Available on crate feature poem-openapi only.
pub fn nanoid(self) -> ZString
poem-openapi only.Must be a valid Nano ID (alphanumeric + _ + -).
Sourcepub fn nanoid_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn nanoid_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a valid Nano ID (alphanumeric + _ + -).
With a custom error message.
Sourcepub fn emoji(self) -> ZString
Available on crate feature poem-openapi only.
pub fn emoji(self) -> ZString
poem-openapi only.Must be non-empty and consist only of emoji.
Sourcepub fn emoji_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn emoji_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be non-empty and consist only of emoji.
With a custom error message.
Sourcepub fn country(self) -> ZString
Available on crate feature poem-openapi only.
pub fn country(self) -> ZString
poem-openapi only.Must be an assigned ISO 3166-1 alpha-2 country code (US, DE; uppercase). country_code checks only the shape.
Sourcepub fn country_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn country_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn country_alpha3(self) -> ZString
Available on crate feature poem-openapi only.
pub fn country_alpha3(self) -> ZString
poem-openapi only.Must be an assigned ISO 3166-1 alpha-3 country code (USA, DEU; uppercase).
Sourcepub fn country_alpha3_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn country_alpha3_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be an assigned ISO 3166-1 alpha-3 country code (USA, DEU; uppercase).
With a custom error message.
Sourcepub fn iban(self) -> ZString
Available on crate feature poem-openapi only.
pub fn iban(self) -> ZString
poem-openapi only.Must be an IBAN: uppercase, optional single spaces between groups, the country’s registry length and a valid mod-97 checksum.
Sourcepub fn iban_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn iban_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn bic(self) -> ZString
Available on crate feature poem-openapi only.
pub fn bic(self) -> ZString
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.
Sourcepub fn bic_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn bic_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn isbn(self) -> ZString
Available on crate feature poem-openapi only.
pub fn isbn(self) -> ZString
poem-openapi only.Must be an ISBN-10 or ISBN-13 with a valid check digit (single - / space separators allowed).
Sourcepub fn isbn_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn isbn_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn ean(self) -> ZString
Available on crate feature poem-openapi only.
pub fn ean(self) -> ZString
poem-openapi only.Must be an EAN / GTIN: 8, 12, 13 or 14 digits with a valid GS1 check digit.
Sourcepub fn ean_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ean_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn vin(self) -> ZString
Available on crate feature poem-openapi only.
pub fn vin(self) -> ZString
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.
Sourcepub fn vin_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn vin_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn timezone(self) -> ZString
Available on crate feature poem-openapi only.
pub fn timezone(self) -> ZString
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.
Sourcepub fn timezone_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn timezone_msg(self, msg: impl Into<String>) -> ZString
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.
Sourcepub fn mime(self) -> ZString
Available on crate feature poem-openapi only.
pub fn mime(self) -> ZString
poem-openapi only.Must be a media type: type/subtype[+suffix] with optional ; name=value parameters.
Sourcepub fn mime_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn mime_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a media type: type/subtype[+suffix] with optional ; name=value parameters.
With a custom error message.
Sourcepub fn object_id(self) -> ZString
Available on crate feature poem-openapi only.
pub fn object_id(self) -> ZString
poem-openapi only.Must be a MongoDB ObjectId (24 hex digits).
Sourcepub fn object_id_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn object_id_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must be a MongoDB ObjectId (24 hex digits).
With a custom error message.
Source§impl ZString
impl ZString
Sourcepub fn new() -> ZString
Available on crate feature poem-openapi only.
pub fn new() -> ZString
poem-openapi only.Create the schema (the same as its vld:: constructor function).
Sourcepub fn type_error(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn type_error(self, msg: impl Into<String>) -> ZString
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!"));Sourcepub fn with_messages<F>(self, f: F) -> ZString
Available on crate feature poem-openapi only.
pub fn with_messages<F>(self, f: F) -> ZString
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,
});Sourcepub fn min(self, len: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn min(self, len: usize) -> ZString
poem-openapi only.Minimum string length in characters (inclusive).
Sourcepub fn min_bytes(self, n: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn min_bytes(self, n: usize) -> ZString
poem-openapi only.Minimum UTF-8 length in bytes (too_small, origin bytes):
for byte-limited storage. min counts characters.
Sourcepub fn max_bytes(self, n: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn max_bytes(self, n: usize) -> ZString
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 bytesSourcepub fn min_msg(self, len: usize, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn min_msg(self, len: usize, msg: impl Into<String>) -> ZString
poem-openapi only.Minimum string length with custom message.
Sourcepub fn max(self, len: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn max(self, len: usize) -> ZString
poem-openapi only.Maximum string length in characters (inclusive).
Sourcepub fn max_msg(self, len: usize, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn max_msg(self, len: usize, msg: impl Into<String>) -> ZString
poem-openapi only.Maximum string length with custom message.
Sourcepub fn len(self, len: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn len(self, len: usize) -> ZString
poem-openapi only.Exact string length in characters.
Sourcepub fn len_msg(self, len: usize, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn len_msg(self, len: usize, msg: impl Into<String>) -> ZString
poem-openapi only.Exact string length with custom message.
Sourcepub fn rule(self, rule: impl Rule<str>) -> ZString
Available on crate feature poem-openapi only.
pub fn rule(self, rule: impl Rule<str>) -> ZString
poem-openapi only.Check with a reusable Rule on the string
(keeps the ZString builder; see vld::rules).
Sourcepub fn rule_msg(self, rule: impl Rule<str>, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn rule_msg(self, rule: impl Rule<str>, msg: impl Into<String>) -> ZString
poem-openapi only.rule with a custom message.
Sourcepub fn starts_with(self, prefix: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn starts_with(self, prefix: impl Into<String>) -> ZString
poem-openapi only.Must start with the given prefix.
Sourcepub fn starts_with_msg(
self,
prefix: impl Into<String>,
msg: impl Into<String>,
) -> ZString
Available on crate feature poem-openapi only.
pub fn starts_with_msg( self, prefix: impl Into<String>, msg: impl Into<String>, ) -> ZString
poem-openapi only.Must start with the given prefix, with custom message.
Sourcepub fn ends_with(self, suffix: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn ends_with(self, suffix: impl Into<String>) -> ZString
poem-openapi only.Must end with the given suffix.
Sourcepub fn ends_with_msg(
self,
suffix: impl Into<String>,
msg: impl Into<String>,
) -> ZString
Available on crate feature poem-openapi only.
pub fn ends_with_msg( self, suffix: impl Into<String>, msg: impl Into<String>, ) -> ZString
poem-openapi only.Must end with the given suffix, with custom message.
Sourcepub fn contains(self, sub: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn contains(self, sub: impl Into<String>) -> ZString
poem-openapi only.Must contain the given substring.
Sourcepub fn contains_msg(
self,
sub: impl Into<String>,
msg: impl Into<String>,
) -> ZString
Available on crate feature poem-openapi only.
pub fn contains_msg( self, sub: impl Into<String>, msg: impl Into<String>, ) -> ZString
poem-openapi only.Must contain the given substring, with custom message.
Sourcepub fn non_empty(self) -> ZString
Available on crate feature poem-openapi only.
pub fn non_empty(self) -> ZString
poem-openapi only.Must not be empty.
Sourcepub fn non_empty_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn non_empty_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.Must not be empty, with custom message.
Sourcepub fn trim(self) -> ZString
Available on crate feature poem-openapi only.
pub fn trim(self) -> ZString
poem-openapi only.Trim whitespace before validation.
Sourcepub fn to_lowercase(self) -> ZString
Available on crate feature poem-openapi only.
pub fn to_lowercase(self) -> ZString
poem-openapi only.Convert to lowercase before validation.
Sourcepub fn truncate(self, n: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn truncate(self, n: usize) -> ZString
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");Sourcepub fn to_uppercase(self) -> ZString
Available on crate feature poem-openapi only.
pub fn to_uppercase(self) -> ZString
poem-openapi only.Convert to uppercase before validation.
Sourcepub fn require_lowercase(self) -> ZString
Available on crate feature poem-openapi only.
pub fn require_lowercase(self) -> ZString
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"));Sourcepub fn require_lowercase_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn require_lowercase_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.require_lowercase with a custom message.
Sourcepub fn require_uppercase(self) -> ZString
Available on crate feature poem-openapi only.
pub fn require_uppercase(self) -> ZString
poem-openapi only.Password rule: at least one uppercase letter (Unicode Uppercase).
Sourcepub fn require_uppercase_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn require_uppercase_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.require_uppercase with a custom message.
Sourcepub fn require_digit(self) -> ZString
Available on crate feature poem-openapi only.
pub fn require_digit(self) -> ZString
poem-openapi only.Password rule: at least one ASCII digit.
Sourcepub fn require_digit_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn require_digit_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.require_digit with a custom message.
Sourcepub fn require_symbol(self) -> ZString
Available on crate feature poem-openapi only.
pub fn require_symbol(self) -> ZString
poem-openapi only.Password rule: at least one symbol — a character that is neither
alphanumeric nor whitespace (!, _, €, …).
Sourcepub fn require_symbol_msg(self, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn require_symbol_msg(self, msg: impl Into<String>) -> ZString
poem-openapi only.require_symbol with a custom message.
Sourcepub fn max_repeat(self, n: usize) -> ZString
Available on crate feature poem-openapi only.
pub fn max_repeat(self, n: usize) -> ZString
poem-openapi only.Password rule: no character repeated more than n times in a row
(max_repeat(2) rejects aaa).
Sourcepub fn max_repeat_msg(self, n: usize, msg: impl Into<String>) -> ZString
Available on crate feature poem-openapi only.
pub fn max_repeat_msg(self, n: usize, msg: impl Into<String>) -> ZString
poem-openapi only.max_repeat with a custom message.
Sourcepub fn coerce(self) -> ZString
Available on crate feature poem-openapi only.
pub fn coerce(self) -> ZString
poem-openapi only.Coerce non-string values (numbers, booleans) to string.
Sourcepub fn coerce_bools(
self,
on: impl Into<String>,
off: impl Into<String>,
) -> ZString
Available on crate feature poem-openapi only.
pub fn coerce_bools( self, on: impl Into<String>, off: impl Into<String>, ) -> ZString
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 CollectNestedSchemas for ZString
Available on crate feature openapi only.
impl CollectNestedSchemas for ZString
openapi only.Source§impl JsonSchema for ZString
Available on crate feature openapi only.Generate a JSON Schema representation of this string schema.
impl JsonSchema for ZString
openapi only.Generate a JSON Schema representation of this string schema.
- Length bounds: the strictest
min/max/len/non_emptywins. - Formats: the first goes into
format, further ones intoallOf. pattern/starts_with/ends_with/containsbecomepatterns (first inpattern, further ones inallOf).- Password rules add
format: "password"and anx-passwordobject (lowercase,uppercase,digit,symbol:true;maxRepeat,minScore: numbers).
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
Source§fn is_required(&self) -> bool
fn is_required(&self) -> bool
required array. Read moreSource§impl VldSchema for ZString
impl VldSchema for ZString
Source§fn parse_value(&self, value: &Value) -> Result<String, VldError>
fn parse_value(&self, value: &Value) -> Result<String, VldError>
serde_json::Value.Source§fn parse_missing(&self) -> Result<Self::Output, VldError>
fn parse_missing(&self) -> Result<Self::Output, VldError>
Source§fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
fn parse<I>(&self, input: &I) -> Result<Self::Output, VldError>
serde_json::Value, etc.)Source§fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>where
T: Serialize,
fn validate<T>(&self, value: &T) -> Result<Self::Output, VldError>where
T: Serialize,
Source§fn is_valid<T>(&self, value: &T) -> boolwhere
T: Serialize,
fn is_valid<T>(&self, value: &T) -> boolwhere
T: Serialize,
Source§fn optional(self) -> ZOptional<Self>
fn optional(self) -> ZOptional<Self>
None.Source§fn with_default(self, value: Self::Output) -> ZDefault<Self>
fn with_default(self, value: Self::Output) -> ZDefault<Self>
Source§fn blank_as(self, value: Self::Output) -> ZDefault<Self>
fn blank_as(self, value: Self::Output) -> ZDefault<Self>
with_default, and a blank string (empty or
whitespace only) also becomes value: legacy stores that write ""
or null for “unset”. Read moreSource§fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
fn refine<F>(self, check: F, message: &str) -> ZRefine<Self, F>
Source§fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
fn rule_msg<R>(self, rule: R, msg: impl Into<String>) -> ZRule<Self, R>
rule with a custom error message.Source§fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
fn try_transform<F, U, E>(self, f: F) -> ZTryTransform<Self, F, U>
Err becomes a
validation issue (Custom { code: "transform" }, message = the error). Read moreSource§fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
fn transform<F, U>(self, f: F) -> ZTransform<Self, F, U>
Source§fn catch(self, fallback: Self::Output) -> ZCatch<Self>
fn catch(self, fallback: Self::Output) -> ZCatch<Self>
Source§fn pipe<S>(self, next: S) -> ZPipe<Self, S>
fn pipe<S>(self, next: S) -> ZPipe<Self, S>
Source§fn describe(self, description: &str) -> ZDescribe<Self>
fn describe(self, description: &str) -> ZDescribe<Self>
Source§fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
fn super_refine<F>(self, check: F) -> ZSuperRefine<Self, F>
Source§fn or<B>(self, other: B) -> ZUnion2<Self, B>where
B: VldSchema,
fn or<B>(self, other: B) -> ZUnion2<Self, B>where
B: VldSchema,
Either<Self::Output, B::Output>.Source§fn and<B>(self, other: B) -> ZIntersection<Self, B>where
B: VldSchema,
fn and<B>(self, other: B) -> ZIntersection<Self, B>where
B: VldSchema,
Auto Trait Implementations§
impl !RefUnwindSafe for ZString
impl !UnwindSafe for ZString
impl Forget for ZString
impl Freeze for ZString
impl Move for ZString
impl Send for ZString
impl Sync for ZString
impl Unpin for ZString
impl UnsafeUnpin for ZString
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> DynSchema for T
impl<T> DynSchema for T
Source§fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>
fn dyn_parse(&self, value: &Value) -> Result<Value, VldError>
value and return the output serialized back to JSON.Source§fn dyn_parse_missing(&self) -> Result<Value, VldError>
fn dyn_parse_missing(&self) -> Result<Value, VldError>
VldSchema::parse_missing of the erased schema.Source§fn dyn_json_schema(&self) -> Value
fn dyn_json_schema(&self) -> Value
openapi only.Source§fn dyn_is_required(&self) -> bool
fn dyn_is_required(&self) -> bool
openapi only.required array.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> ⓘ
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