Enum schema_analysis::Schema
source · pub enum Schema {
Null(NullContext),
Boolean(BooleanContext),
Integer(NumberContext<i128>),
Float(NumberContext<f64>),
String(StringContext),
Bytes(BytesContext),
Sequence {
field: Box<Field>,
context: SequenceContext,
},
Struct {
fields: BTreeMap<String, Field>,
context: MapStructContext,
},
Union {
variants: Vec<Schema>,
},
}
Expand description
This enum is the core output of the analysis, it describes the structure of a document.
Each variant also contains context data that allows it to store information about the values it has encountered.
Variants§
Null(NullContext)
The Null variant is a special one that is only ever found when a document has a single null value at the root of the document. Null values in Structs or Sequences are instead handled at the Field level, where it is more ergonomic.
Boolean(BooleanContext)
Represents a boolean value.
Integer(NumberContext<i128>)
Represents an integer value.
Float(NumberContext<f64>)
Represents a floating point value.
String(StringContext)
Represents a textual value.
Bytes(BytesContext)
Represents a value of raw bytes.
Sequence
Fields
context: SequenceContext
The context aggregates information about the sequence. It is passed the length of the sequence.
Represents a sequence of values described by a Field. It assumes all values share the same schema.
Struct
Fields
context: MapStructContext
The context aggregates information about the struct. It is passed a vector of the key names.
Represents a String->Field mapping.
Note: currently there is not a true map and only strings may be used as keys.
Union
Simply a vector of Schemas, it should never contain an Union or multiple instances of the same variant inside.
Note: content needs to be a struct variant to work with #[serde(tag = "type")]
.
Implementations§
source§impl Schema
impl Schema
sourcepub fn to_json_typegen_shape(&self) -> Shape
pub fn to_json_typegen_shape(&self) -> Shape
sourcepub fn process_with_json_typegen(
&self,
mode: OutputMode
) -> Result<String, JTError>
pub fn process_with_json_typegen(
&self,
mode: OutputMode
) -> Result<String, JTError>
Convert a Schema to a supported json_typegen output
source§impl Schema
impl Schema
sourcepub fn to_json_schema_with_schemars(&self) -> Result<String, impl Error>
pub fn to_json_schema_with_schemars(&self) -> Result<String, impl Error>
Convert into a json_schema using the default settings.
sourcepub fn to_json_schema_with_schemars_version(
&self,
version: &JsonSchemaVersion
) -> Result<String, impl Error>
pub fn to_json_schema_with_schemars_version(
&self,
version: &JsonSchemaVersion
) -> Result<String, impl Error>
Convert into a specific version of json_schema.
sourcepub fn to_schemars_schema(&self, generator: &mut SchemaGenerator) -> RootSchema
pub fn to_schemars_schema(&self, generator: &mut SchemaGenerator) -> RootSchema
Convert using a provided generator (which also holds the settings) to a json schema.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq<Schema> for Schema
impl PartialEq<Schema> for Schema
source§impl StructuralEq<Schema> for Schema
impl StructuralEq<Schema> for Schema
source§fn structural_eq(&self, other: &Self) -> bool
fn structural_eq(&self, other: &Self) -> bool
true
if self
and other
share the same structure.source§fn structural_ne(&self, other: &Rhs) -> bool
fn structural_ne(&self, other: &Rhs) -> bool
true
if self
and other
DO NOT share the same structure.Auto Trait Implementations§
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> CoalesceAny for Twhere
T: Coalesce + 'static,
impl<T> CoalesceAny for Twhere
T: Coalesce + 'static,
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.