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