valico/json_dsl/
errors.rs

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