valico/json_dsl/
errors.rs

1use std::error::{Error};
2use super::super::common::error::ValicoError;
3use serde_json::{Value, to_value};
4use serde::{Serialize, Serializer};
5
6#[derive(Debug)]
7#[allow(missing_copy_implementations)]
8pub struct Required {
9    pub path: String
10}
11impl_err!(Required, "required", "This field is required");
12impl_serialize!(Required);
13
14
15#[derive(Debug)]
16#[allow(missing_copy_implementations)]
17pub struct WrongType {
18    pub path: String,
19    pub detail: String
20}
21impl_err!(WrongType, "wrong_type", "Type of the value is wrong", +detail);
22impl_serialize!(WrongType);
23
24#[derive(Debug)]
25#[allow(missing_copy_implementations)]
26pub struct WrongValue {
27    pub path: String,
28    pub detail: Option<String>,
29}
30impl_err!(WrongValue, "wrong_value", "The value is wrong or mailformed", +opt_detail);
31impl_serialize!(WrongValue);
32
33#[derive(Debug)]
34#[allow(missing_copy_implementations)]
35pub struct MutuallyExclusive {
36    pub path: String,
37    pub detail: Option<String>,
38    pub params: Vec<String>
39}
40impl_err!(MutuallyExclusive, "mutually_exclusive", "The values are mutually exclusive", +opt_detail);
41impl_serialize!(MutuallyExclusive, |err: &MutuallyExclusive, map: &mut ::serde_json::Map<String, Value>| {
42    map.insert("params".to_string(), to_value(&err.params).unwrap());
43});
44
45#[derive(Debug)]
46#[allow(missing_copy_implementations)]
47pub struct ExactlyOne {
48    pub path: String,
49    pub detail: Option<String>,
50    pub params: Vec<String>
51}
52impl_err!(ExactlyOne, "exactly_one", "Exacly one of the values must be present", +opt_detail);
53impl_serialize!(ExactlyOne, |err: &ExactlyOne, map: &mut ::serde_json::Map<String, Value>| {
54    map.insert("params".to_string(), to_value(&err.params).unwrap())
55});
56
57
58#[derive(Debug)]
59#[allow(missing_copy_implementations)]
60pub struct AtLeastOne {
61    pub path: String,
62    pub detail: Option<String>,
63    pub params: Vec<String>
64}
65impl_err!(AtLeastOne, "at_least_one", "At least one of the values must be present", +opt_detail);
66impl_serialize!(AtLeastOne, |err: &AtLeastOne, map: &mut ::serde_json::Map<String, Value>| {
67    map.insert("params".to_string(), to_value(&err.params).unwrap())
68});