Skip to main content

ValidationErrorKind

Enum ValidationErrorKind 

Source
pub enum ValidationErrorKind {
    TooLong {
        len: usize,
        max: usize,
    },
    TooManyItems {
        len: usize,
        max: usize,
    },
    TooFewItems {
        len: usize,
        min: usize,
    },
    BelowMinimum {
        value: f64,
        min: f64,
    },
    AboveMaximum {
        value: f64,
        max: f64,
    },
    NotMultipleOf {
        value: f64,
        multiple: f64,
    },
}
Expand description

What was wrong with the value.

The numeric variants carry f64 for uniformity across integer and number fields; comparison itself is done in the field’s own type, so an integer bound is never decided in floating point.

Variants§

§

TooLong

A string longer than its schema’s maxLength, counted in characters.

Fields

§len: usize
§max: usize
§

TooManyItems

An array longer than its schema’s maxItems.

Fields

§len: usize
§max: usize
§

TooFewItems

An array shorter than its schema’s minItems.

Fields

§len: usize
§min: usize
§

BelowMinimum

A number below its schema’s minimum.

Fields

§value: f64
§min: f64
§

AboveMaximum

A number above its schema’s maximum.

Fields

§value: f64
§max: f64
§

NotMultipleOf

A number that is not a whole multiple of its schema’s multipleOf.

Fields

§value: f64
§multiple: f64

Implementations§

Source§

impl ValidationErrorKind

Source

pub fn constraint_class(&self) -> ConstraintClass

Which OCPP constraint category this violates, and so which CALLERROR code answers it. See ConstraintClass.

Examples found in repository?
examples/validate.rs (line 42)
9fn main() {
10    let mut request: AuthorizeRequest = AuthorizeRequest {
11        certificate: None,
12        custom_data: None,
13        id_token: IdToken {
14            additional_info: None,
15            custom_data: None,
16            // Bounded at `maxLength: 36` by the schema, so this is a
17            // `heapless::String<36>` and an over-long value can't be built
18            // in the first place -- nothing for `validate` to check.
19            id_token: heapless::String::try_from("ABC123").unwrap(),
20            r#type: IdTokenEnum::ISO14443,
21        },
22        iso15118_certificate_hash_data: None,
23    };
24
25    println!("conformant: {:?}", request.validate());
26
27    // `certificate` is `maxLength: 5500` in the schema, but 5500 is too
28    // large to inline as a `heapless::String`, so with `alloc` it is a
29    // plain growable `String`. The type accepts this; the spec does not.
30    request.certificate = Some("-".repeat(6000));
31
32    match request.validate() {
33        Ok(()) => println!("no violations"),
34        Err(error) => {
35            println!("rejected: {error}");
36            println!("  kind:    {:?}", error.kind());
37            println!("  path:    {:?}", error.path());
38
39            // Which `CALLERROR` a CSMS answers with. The code's spelling is
40            // version-specific (1.6J dropped an `r` from "occurrence"), so
41            // the classification is what's shared.
42            let code = match error.kind().constraint_class() {
43                ConstraintClass::Property => "PropertyConstraintViolation",
44                ConstraintClass::Occurrence => "OccurrenceConstraintViolation",
45            };
46            println!("  answer:  {code}");
47        }
48    }
49
50    // `minItems: 1` is the other half: no collection type can say "at least
51    // one", so an empty required array is only caught here.
52    request.certificate = None;
53    request.iso15118_certificate_hash_data = Some(heapless::Vec::new());
54
55    if let Err(error) = request.validate() {
56        println!("rejected: {error}");
57    }
58}

Trait Implementations§

Source§

impl Clone for ValidationErrorKind

Source§

fn clone(&self) -> ValidationErrorKind

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 Copy for ValidationErrorKind

Source§

impl Debug for ValidationErrorKind

Source§

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

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

impl Display for ValidationErrorKind

Source§

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

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

impl PartialEq for ValidationErrorKind

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ValidationErrorKind

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.