1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::fmt;
use std::str;

#[macro_use]
pub mod helpers;
#[macro_use]
pub mod keywords;
pub mod builder;
pub mod errors;
pub mod schema;
pub mod scope;
pub mod validators;

pub use self::builder::{schema, Builder};
pub use self::schema::{Schema, SchemaError};
pub use self::scope::Scope;
pub use self::validators::ValidationState;

#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd)]
/// Represents the schema version to use.
pub enum SchemaVersion {
    /// Use draft 7.
    Draft7,
    /// Use draft 2019-09.
    Draft2019_09,
}

#[derive(Copy, Debug, Clone)]
pub enum PrimitiveType {
    Array,
    Boolean,
    Integer,
    Number,
    Null,
    Object,
    String,
}

impl str::FromStr for PrimitiveType {
    type Err = ();
    fn from_str(s: &str) -> Result<PrimitiveType, ()> {
        match s {
            "array" => Ok(PrimitiveType::Array),
            "boolean" => Ok(PrimitiveType::Boolean),
            "integer" => Ok(PrimitiveType::Integer),
            "number" => Ok(PrimitiveType::Number),
            "null" => Ok(PrimitiveType::Null),
            "object" => Ok(PrimitiveType::Object),
            "string" => Ok(PrimitiveType::String),
            _ => Err(()),
        }
    }
}

impl fmt::Display for PrimitiveType {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.write_str(match self {
            PrimitiveType::Array => "array",
            PrimitiveType::Boolean => "boolean",
            PrimitiveType::Integer => "integer",
            PrimitiveType::Number => "number",
            PrimitiveType::Null => "null",
            PrimitiveType::Object => "object",
            PrimitiveType::String => "string",
        })
    }
}