pub struct Schema { /* private fields */ }Expand description
A schema for validating top-level JSON objects.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn field(
self,
name: impl Into<String>,
validator: impl Validator + 'static,
) -> Self
pub fn field( self, name: impl Into<String>, validator: impl Validator + 'static, ) -> Self
Add a field validator.
Sourcepub fn strict(self, strict: bool) -> Self
pub fn strict(self, strict: bool) -> Self
Enable or disable strict mode.
When strict, keys present in the input object but absent from the schema
produce an Unknown field error.
Sourcepub fn fail_fast(self, fail_fast: bool) -> Self
pub fn fail_fast(self, fail_fast: bool) -> Self
Stop at the first validation error.
When enabled, validation returns a result containing exactly one error. The flag is propagated to nested validators.
Sourcepub fn validate(&self, data: &Value) -> ValidationResult
pub fn validate(&self, data: &Value) -> ValidationResult
Validate a JSON object (serde_json::Value object).
Sourcepub fn validate_or_raise(&self, data: &Value) -> Result<(), ValidationResult>
pub fn validate_or_raise(&self, data: &Value) -> Result<(), ValidationResult>
Validate and return Ok(()) if valid, or the full result on failure.
Sourcepub fn try_validate(&self, data: &Value) -> Result<(), ValidationErrors>
pub fn try_validate(&self, data: &Value) -> Result<(), ValidationErrors>
Validate and return Ok(()) if valid, or a ValidationErrors
aggregate (which implements std::error::Error) on failure.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Schema
impl !UnwindSafe for Schema
impl Freeze for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
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