Struct jsonparser::JSONSchema
source · pub struct JSONSchema<'a> { /* private fields */ }Implementations§
source§impl<'a> JSONSchema<'a>
impl<'a> JSONSchema<'a>
sourcepub fn new<T: Into<HashMap<&'a str, Box<dyn Validator>>>>(rules: T) -> Self
pub fn new<T: Into<HashMap<&'a str, Box<dyn Validator>>>>(rules: T) -> Self
Create a new JSONSchema instance with the given rules.
§Example
use jsonparser::{JSONSchema, StringType, NumberType};
let schema = JSONSchema::new([
("name", StringType::new().min_length(6).boxed()),
("age", NumberType::new().gt(18.0).boxed())
]);sourcepub fn validate(&self, value: &JSONValue) -> Result<(), String>
pub fn validate(&self, value: &JSONValue) -> Result<(), String>
Validate the given JSONValue against the schema.
§Example
use jsonparser::{JSONValue, JSONSchema, StringType, NumberType};
let schema = JSONSchema::new([
("name", StringType::new().min_length(6).boxed()),
("age", NumberType::new().gt(18.0).boxed())
]);
let json = JSONValue::Object({ /* ... */ });
match schema.validate(&json) {
Ok(_) => println!("Valid JSON"),
Err(e) => eprintln!("Invalid JSON: {}", e)
}Auto Trait Implementations§
impl<'a> !RefUnwindSafe for JSONSchema<'a>
impl<'a> !Send for JSONSchema<'a>
impl<'a> !Sync for JSONSchema<'a>
impl<'a> Unpin for JSONSchema<'a>
impl<'a> !UnwindSafe for JSONSchema<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more