Skip to main content

valico/json_schema/
mod.rs

1use std::fmt;
2use std::str;
3
4#[macro_use]
5pub mod helpers;
6#[macro_use]
7pub mod keywords;
8pub mod builder;
9pub mod errors;
10pub mod schema;
11pub mod scope;
12pub mod validators;
13
14pub use self::builder::{schema, Builder};
15pub use self::schema::{Schema, SchemaError};
16pub use self::scope::Scope;
17pub use self::validators::ValidationState;
18
19#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd)]
20/// Represents the schema version to use.
21pub enum SchemaVersion {
22    /// Use draft 7.
23    Draft7,
24    /// Use draft 2019-09.
25    Draft2019_09,
26}
27
28#[derive(Copy, Debug, Clone)]
29pub enum PrimitiveType {
30    Array,
31    Boolean,
32    Integer,
33    Number,
34    Null,
35    Object,
36    String,
37}
38
39impl str::FromStr for PrimitiveType {
40    type Err = ();
41    fn from_str(s: &str) -> Result<PrimitiveType, ()> {
42        match s {
43            "array" => Ok(PrimitiveType::Array),
44            "boolean" => Ok(PrimitiveType::Boolean),
45            "integer" => Ok(PrimitiveType::Integer),
46            "number" => Ok(PrimitiveType::Number),
47            "null" => Ok(PrimitiveType::Null),
48            "object" => Ok(PrimitiveType::Object),
49            "string" => Ok(PrimitiveType::String),
50            _ => Err(()),
51        }
52    }
53}
54
55impl fmt::Display for PrimitiveType {
56    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
57        fmt.write_str(match self {
58            PrimitiveType::Array => "array",
59            PrimitiveType::Boolean => "boolean",
60            PrimitiveType::Integer => "integer",
61            PrimitiveType::Number => "number",
62            PrimitiveType::Null => "null",
63            PrimitiveType::Object => "object",
64            PrimitiveType::String => "string",
65        })
66    }
67}