Skip to main content

IssueCode

Enum IssueCode 

Source
#[non_exhaustive]
pub enum IssueCode {
Show 40 variants InvalidType { expected: String, received: String, }, TooSmall { origin: SizeOrigin, minimum: Value, inclusive: bool, }, TooBig { origin: SizeOrigin, maximum: Value, inclusive: bool, }, InvalidLength { origin: SizeOrigin, expected: usize, }, InvalidString { validation: StringValidation, }, InvalidFormat { format: FormatKind, }, InvalidDate { kind: DateKind, }, InvalidTimezoneOffset { expected: String, }, NotInPast { kind: DateKind, }, NotInFuture { kind: DateKind, }, NotInt, NotFinite, NotMultipleOf { divisor: Value, }, NotSafeInteger, InvalidLiteral { expected: Value, }, InvalidEnumValue { options: Vec<String>, }, InvalidUnion, InvalidDiscriminator { options: Vec<Value>, }, NotUnique, MissingContains, DuplicateKey, InvalidMapEntry, MissingField, UnrecognizedField, PathOutsideBase { base: String, }, PathNotAbsolute, PathNotRelative, PathNotFound, PathNotFile, PathNotDir, JsonTooDeep { max_depth: usize, }, FileTypeNotAllowed { kind: FileTypeKind, actual: String, allowed: Vec<String>, }, FileTypeDenied { kind: FileTypeKind, actual: String, }, FileTypeUnknown { kind: FileTypeKind, }, ChecksumMismatch { algorithm: String, }, MissingExif, SerializeError { detail: String, }, IoError, ParseError, Custom { code: String, },
}
Expand description

Validation issue code — describes what went wrong.

Every variant except Custom is produced by vld itself; Custom is reserved for user-defined codes (refine, custom, super_refine, IssueBuilder). See the module docs for the key of every variant.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

InvalidType

Wrong JSON type.

Fields

§expected: String
§received: String
§

TooSmall

Below a lower bound. minimum is a JSON number, or a string for Decimal / Date / DateTime origins.

Fields

§origin: SizeOrigin
§minimum: Value
§inclusive: bool
§

TooBig

Above an upper bound (see TooSmall).

Fields

§origin: SizeOrigin
§maximum: Value
§inclusive: bool
§

InvalidLength

Exact length mismatch.

Fields

§origin: SizeOrigin
§expected: usize
§

InvalidString

String format / content check failed.

Fields

§validation: StringValidation
§

InvalidFormat

A non-string schema could not parse its textual format.

Fields

§format: FormatKind
§

InvalidDate

Not a valid date / datetime.

Fields

§

InvalidTimezoneOffset

Datetime offset differs from the required one (±HH:MM).

Fields

§expected: String
§

NotInPast

Date / datetime is not in the past.

Fields

§

NotInFuture

Date / datetime is not in the future.

Fields

§

NotInt

Number is not an integer.

§

NotFinite

Number is NaN or infinite.

§

NotMultipleOf

Number is not a multiple of divisor.

Fields

§divisor: Value
§

NotSafeInteger

Number is outside -(2^53-1)..=2^53-1.

§

InvalidLiteral

Value differs from the literal.

Fields

§expected: Value
§

InvalidEnumValue

String is not one of the enum options.

Fields

§options: Vec<String>
§

InvalidUnion

No union variant matched (followed by every variant’s issues).

§

InvalidDiscriminator

Discriminator value matches no variant.

Fields

§options: Vec<Value>
§

NotUnique

Array item repeats an earlier one (unique()).

§

MissingContains

Array lacks the contains(...) value.

§

DuplicateKey

Map key repeats an earlier one.

§

InvalidMapEntry

Map entry is not a [key, value] pair.

§

MissingField

Required field is missing or null.

§

UnrecognizedField

Field not declared by a strict object.

§

PathOutsideBase

Path escapes the within(base) directory.

Fields

§base: String
§

PathNotAbsolute

Path must be absolute.

§

PathNotRelative

Path must be relative.

§

PathNotFound

Path does not exist (exists(), file(), dir(), vld::file()).

§

PathNotFile

Path exists but is not a regular file.

§

PathNotDir

Path exists but is not a directory.

§

JsonTooDeep

JSON nesting is deeper than max_depth.

Fields

§max_depth: usize
§

FileTypeNotAllowed

File extension / media type / magic type is not in the allow list.

Fields

§actual: String
§allowed: Vec<String>
§

FileTypeDenied

File extension / media type / magic type is on the deny list.

Fields

§actual: String
§

FileTypeUnknown

File media / magic type could not be detected.

Fields

§

ChecksumMismatch

File hash differs (algorithm is "SHA-256" or "MD5").

Fields

§algorithm: String
§

MissingExif

Image has no EXIF metadata.

§

SerializeError

A validated value could not be serialized to JSON.

Fields

§detail: String
§

IoError

Filesystem error.

§

ParseError

Input is not valid JSON.

§

Custom

User-defined code.

Fields

§code: String

Implementations§

Source§

impl IssueCode

Source

pub fn key(&self) -> &str

Stable snake_case key for this code (the user code for Custom).

Source

pub fn message_keys(&self) -> Vec<String>

Message-template keys, most specific first.

E.g. ["too_small.string", "too_small"]; exclusive bounds use too_small_exclusive / too_big_exclusive; Custom codes fall back to "custom". Resolvers (MessageResolver) are asked in this order.

Source

pub fn plural_count(&self) -> Option<u64>

Count selecting a plural template variant: the minimum / maximum of too_small / too_big or the expected of invalid_length, when it is a non-negative integer.

Source

pub fn params(&self) -> Vec<(&'static str, String)>

Key-value parameters for message templates ({minimum}, {expected}, …).

Source

pub fn default_message(&self) -> String

Default English message, rendered from the english() template table and params().

Size checks with a count of 1 use the _one variant ("String must be exactly 1 character"); invalid_type type keys render through their type.<key> label when one exists.

Trait Implementations§

Source§

impl Clone for IssueCode

Source§

fn clone(&self) -> IssueCode

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 Debug for IssueCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for IssueCode

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<IssueCode, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for IssueCode

Source§

fn eq(&self, other: &IssueCode) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for IssueCode

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for IssueCode

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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