pub enum Schema {
String {
min_length: Option<usize>,
max_length: Option<usize>,
pattern: Option<String>,
allowed_values: Option<SmallVec<[String; 8]>>,
},
Integer {
minimum: Option<i64>,
maximum: Option<i64>,
},
Number {
minimum: Option<f64>,
maximum: Option<f64>,
},
Boolean,
Null,
Array {
items: Option<Box<Schema>>,
min_items: Option<usize>,
max_items: Option<usize>,
unique_items: bool,
},
Object {
properties: HashMap<String, Schema>,
required: Vec<String>,
additional_properties: bool,
},
OneOf {
schemas: SmallVec<[Box<Schema>; 4]>,
},
AllOf {
schemas: SmallVec<[Box<Schema>; 4]>,
},
Any,
}Expand description
JSON Schema representation for validation
Supports a practical subset of JSON Schema Draft 2020-12 focused on validation needs for streaming JSON data.
§Design Philosophy
- Focused on validation, not full JSON Schema specification
- Performance-oriented with pre-compiled validation rules
- Zero-copy where possible using Arc for shared data
- Type-safe with strongly-typed enum variants
§Examples
let schema = Schema::Object {
properties: vec![
("id".to_string(), Schema::Integer { minimum: Some(1), maximum: None }),
("name".to_string(), Schema::String {
min_length: Some(1),
max_length: Some(100),
pattern: None,
allowed_values: None,
}),
].into_iter().collect(),
required: vec!["id".to_string(), "name".to_string()],
additional_properties: false,
};Variants§
String
String type with optional constraints
Fields
Integer
Integer type with optional range constraints
Number
Number type (float/double) with optional range constraints
Boolean
Boolean type (no constraints)
Null
Null type (no constraints)
Array
Array type with element schema and size constraints
Fields
Object
Object type with property schemas
Fields
OneOf
Union type (one of multiple schemas)
AllOf
Intersection type (all of multiple schemas)
Any
Any type (no validation)
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn allows_type(&self, schema_type: SchemaType) -> bool
pub fn allows_type(&self, schema_type: SchemaType) -> bool
Sourcepub fn validation_cost(&self) -> usize
pub fn validation_cost(&self) -> usize
Get estimated validation cost for performance optimization
Higher cost indicates more expensive validation operations. Used by validation scheduler to optimize validation order.
§Returns
Validation cost estimate (0-1000 range)
Sourcepub fn string(min_length: Option<usize>, max_length: Option<usize>) -> Schema
pub fn string(min_length: Option<usize>, max_length: Option<usize>) -> Schema
Create a simple string schema with length constraints
Sourcepub fn integer(minimum: Option<i64>, maximum: Option<i64>) -> Schema
pub fn integer(minimum: Option<i64>, maximum: Option<i64>) -> Schema
Create a simple integer schema with range constraints
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Schema, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Schema, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<&Schema> for SchemaDefinitionDto
impl From<&Schema> for SchemaDefinitionDto
Source§impl From<&Schema> for SchemaType
impl From<&Schema> for SchemaType
Source§fn from(schema: &Schema) -> SchemaType
fn from(schema: &Schema) -> SchemaType
Source§impl From<SchemaDefinitionDto> for Schema
impl From<SchemaDefinitionDto> for Schema
Source§fn from(dto: SchemaDefinitionDto) -> Self
fn from(dto: SchemaDefinitionDto) -> Self
Source§impl Serialize for Schema
impl Serialize for Schema
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Schema
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more