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.
TooManyItems
An array longer than its schema’s maxItems.
TooFewItems
An array shorter than its schema’s minItems.
BelowMinimum
A number below its schema’s minimum.
AboveMaximum
A number above its schema’s maximum.
NotMultipleOf
A number that is not a whole multiple of its schema’s multipleOf.
Implementations§
Source§impl ValidationErrorKind
impl ValidationErrorKind
Sourcepub fn constraint_class(&self) -> ConstraintClass
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
impl Clone for ValidationErrorKind
Source§fn clone(&self) -> ValidationErrorKind
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ValidationErrorKind
Source§impl Debug for ValidationErrorKind
impl Debug for ValidationErrorKind
Source§impl Display for ValidationErrorKind
impl Display for ValidationErrorKind
Source§impl PartialEq for ValidationErrorKind
impl PartialEq for ValidationErrorKind
impl StructuralPartialEq for ValidationErrorKind
Auto Trait Implementations§
impl Freeze for ValidationErrorKind
impl RefUnwindSafe for ValidationErrorKind
impl Send for ValidationErrorKind
impl Sync for ValidationErrorKind
impl Unpin for ValidationErrorKind
impl UnsafeUnpin for ValidationErrorKind
impl UnwindSafe for ValidationErrorKind
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
Mutably borrows from an owned value. Read more