pub struct Schema { /* private fields */ }Expand description
A compiled spec.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn standard(&self) -> StandardSchema<'_>
pub fn standard(&self) -> StandardSchema<'_>
The Standard Schema V1 surface of this schema.
Source§impl Schema
impl Schema
pub fn new(spec: impl Into<Spec>) -> Schema
Sourcepub fn with_options(spec: impl Into<Spec>, opts: &Options) -> Schema
pub fn with_options(spec: impl Into<Spec>, opts: &Options) -> Schema
Compile a spec, reading it as the options say.
Sourcepub fn parse(src: &str) -> Result<Schema, ExprError>
pub fn parse(src: &str) -> Result<Schema, ExprError>
Compile the string form of a spec: Schema::parse("String.Min(2)").
Sourcepub fn json(&self) -> Result<Value, JsonError>
pub fn json(&self) -> Result<Value, JsonError>
The schema as a JSON Schema document (draft 2020-12).
The declarative JSON of the shape, which crate::expr::build
reads back.
pub fn json_schema(&self) -> Value
Sourcepub fn validate(&self, input: Value) -> Result<Value, ValidationError>
pub fn validate(&self, input: Value) -> Result<Value, ValidationError>
Validate and complete a value: defaults injected, children validated.
Value::Undefined is no value at all, as a bare shape() call is.
Sourcepub fn validate_ctx(
&self,
input: Value,
ctx: &mut Context,
) -> Result<Value, ValidationError>
pub fn validate_ctx( &self, input: Value, ctx: &mut Context, ) -> Result<Value, ValidationError>
validate with a context of the caller’s, for custom validators.
Sourcepub fn valid(&self, input: &Value) -> bool
pub fn valid(&self, input: &Value) -> bool
Whether the value validates. Nothing is produced or rendered.
Sourcepub fn error(&self, input: &Value) -> Vec<FieldError>
pub fn error(&self, input: &Value) -> Vec<FieldError>
The errors of validating the value; empty when it validates.
Source§impl Schema
impl Schema
Sourcepub fn validate_into<T: DeserializeOwned>(
&self,
input: impl Into<Value>,
) -> Result<T, IntoError>
pub fn validate_into<T: DeserializeOwned>( &self, input: impl Into<Value>, ) -> Result<T, IntoError>
Validate, and deserialize the produced value into a type.
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