valico/json_dsl/
mod.rs

1mod builder;
2mod coercers;
3mod param;
4pub mod errors;
5#[macro_use] pub mod validators;
6
7use super::json_schema;
8
9pub use self::param::Param;
10pub use self::builder::Builder;
11pub use self::coercers::{
12    PrimitiveType,
13    Coercer,
14    StringCoercer,
15    I64Coercer,
16    U64Coercer,
17    F64Coercer,
18    BooleanCoercer,
19    NullCoercer,
20    ArrayCoercer,
21    ObjectCoercer,
22};
23
24pub fn i64() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::I64Coercer) }
25pub fn u64() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::U64Coercer) }
26pub fn f64() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::F64Coercer) }
27pub fn string() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::StringCoercer) }
28pub fn boolean() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::BooleanCoercer) }
29pub fn null() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::NullCoercer) }
30pub fn array() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::ArrayCoercer::new()) }
31pub fn array_of(coercer: Box<coercers::Coercer + Send + Sync>) -> Box<coercers::Coercer + Send + Sync> {
32    Box::new(coercers::ArrayCoercer::of_type(coercer))
33}
34
35pub fn encoded_array(separator: &str) -> Box<coercers::Coercer + Send + Sync> {
36    Box::new(coercers::ArrayCoercer::encoded(separator.to_string()))
37}
38
39pub fn encoded_array_of(separator: &str, coercer: Box<coercers::Coercer + Send + Sync>) -> Box<coercers::Coercer + Send + Sync> {
40    Box::new(coercers::ArrayCoercer::encoded_of(separator.to_string(), coercer))
41}
42
43pub fn object() -> Box<coercers::Coercer + Send + Sync> { Box::new(coercers::ObjectCoercer) }
44
45pub struct ExtendedResult<T> {
46    value: T,
47    state: json_schema::ValidationState
48}
49
50impl<T> ExtendedResult<T> {
51    pub fn new(value: T) -> ExtendedResult<T> {
52        ExtendedResult {
53            value: value,
54            state: json_schema::ValidationState::new()
55        }
56    }
57
58    pub fn with_errors(value: T, errors: super::ValicoErrors) -> ExtendedResult<T> {
59        ExtendedResult {
60            value: value,
61            state: json_schema::ValidationState {
62                errors: errors,
63                missing: vec![]
64            }
65        }
66    }
67
68    pub fn is_valid(&self) -> bool {
69        self.state.is_valid()
70    }
71
72    pub fn append(&mut self, second: json_schema::ValidationState) {
73        self.state.append(second);
74    }
75}