Skip to main content

ZString

Struct ZString 

Source
pub struct ZString { /* private fields */ }
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

Must be a valid email address.

Source

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

Must be a valid email address.

With a custom error message.

Source

pub fn url(self) -> ZString

Must be a valid URL (http/https).

Source

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

Must be a valid URL (http/https).

With a custom error message.

Source

pub fn uuid(self) -> ZString

Must be a valid UUID.

Source

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

Must be a valid UUID.

With a custom error message.

Source

pub fn ip(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn slug(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn color(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn currency_code(self) -> ZString

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

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

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

Source

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

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

With a custom error message.

Source

pub fn locale(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn cron(self) -> ZString

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

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

Must be a valid IPv4 address.

Source

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

Must be a valid IPv4 address.

With a custom error message.

Source

pub fn ipv6(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn cidr(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn mac(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn hex(self) -> ZString

Must contain only hexadecimal characters.

Source

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

Must contain only hexadecimal characters.

With a custom error message.

Source

pub fn credit_card(self) -> ZString

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

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

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

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

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

Source

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

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

With a custom error message.

Source

pub fn jwt(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn ascii(self) -> ZString

Must contain only ASCII characters.

Source

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

Must contain only ASCII characters.

With a custom error message.

Source

pub fn alpha(self) -> ZString

Must contain only alphabetic ASCII characters.

Source

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

Must contain only alphabetic ASCII characters.

With a custom error message.

Source

pub fn alphanumeric(self) -> ZString

Must contain only ASCII alphanumeric characters.

Source

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

Must contain only ASCII alphanumeric characters.

With a custom error message.

Source

pub fn lowercase(self) -> ZString

Must already be lowercase.

Source

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

Must already be lowercase.

With a custom error message.

Source

pub fn uppercase(self) -> ZString

Must already be uppercase.

Source

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

Must already be uppercase.

With a custom error message.

Source

pub fn base64(self) -> ZString

Must be a valid (padded) Base64 string.

Source

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

Must be a valid (padded) Base64 string.

With a custom error message.

Source

pub fn base64url(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn json(self) -> ZString

Must be a string containing one valid JSON document.

Source

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

Must be a string containing one valid JSON document.

With a custom error message.

Source

pub fn iso_date(self) -> ZString

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

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

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

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

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

Source

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

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

With a custom error message.

Source

pub fn hostname(self) -> ZString

Must be a valid hostname.

Source

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

Must be a valid hostname.

With a custom error message.

Source

pub fn cuid2(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn ulid(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn nanoid(self) -> ZString

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

Source

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

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

With a custom error message.

Source

pub fn emoji(self) -> ZString

Must be non-empty and consist only of emoji.

Source

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

Must be non-empty and consist only of emoji.

With a custom error message.

Source

pub fn country(self) -> ZString

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Source

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

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

Must be a MongoDB ObjectId (24 hex digits).

Source

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

Must be a MongoDB ObjectId (24 hex digits).

With a custom error message.

Source§

impl ZString

Source

pub fn new() -> ZString

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

Source

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

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,

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

Minimum string length in characters (inclusive).

Source

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

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

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

Minimum string length with custom message.

Source

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

Maximum string length in characters (inclusive).

Source

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

Maximum string length with custom message.

Source

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

Exact string length in characters.

Source

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

Exact string length with custom message.

Source

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

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

rule with a custom message.

Source

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

Must start with the given prefix.

Source

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

Must start with the given prefix, with custom message.

Source

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

Must end with the given suffix.

Source

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

Must end with the given suffix, with custom message.

Source

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

Must contain the given substring.

Source

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

Must contain the given substring, with custom message.

Source

pub fn non_empty(self) -> ZString

Must not be empty.

Source

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

Must not be empty, with custom message.

Source

pub fn trim(self) -> ZString

Trim whitespace before validation.

Source

pub fn to_lowercase(self) -> ZString

Convert to lowercase before validation.

Source

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

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

Convert to uppercase before validation.

Source

pub fn require_lowercase(self) -> ZString

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

require_lowercase with a custom message.

Source

pub fn require_uppercase(self) -> ZString

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

Source

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

require_uppercase with a custom message.

Source

pub fn require_digit(self) -> ZString

Password rule: at least one ASCII digit.

Source

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

require_digit with a custom message.

Source

pub fn require_symbol(self) -> ZString

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

require_symbol with a custom message.

Source

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

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

max_repeat with a custom message.

Source

pub fn coerce(self) -> ZString

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

Source

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

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

Source§

fn default() -> ZString

Returns the “default value” for a type. 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> DynSchema for T
where T: VldSchema, <T as VldSchema>::Output: Serialize,

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§

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> Paint for T
where T: ?Sized,

Source§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
Source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
Source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
Source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
Source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
Source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
Source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
Source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
Source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
Source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
Source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
Source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
Source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
Source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
Source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
Source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
Source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
Source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
Source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
Source§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
Source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
Source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
Source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
Source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
Source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
Source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
Source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
Source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
Source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
Source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
Source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
Source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
Source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
Source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
Source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
Source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
Source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
Source§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling Attribute value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
Source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
Source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
Source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
Source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
Source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
Source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
Source§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi Quirk value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
Source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
Source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
Source§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1:

renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
Source§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
Source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
Source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
Source§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the Condition value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
Source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
Source§

impl<T> Schema for T
where T: VldSchema,

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.