Enum 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

Represents a sequence of values described by a Field. It assumes all values share the same schema.

Fields

§field: Box<Field>

The field is the structure shared by all the elements of the sequence.

§context: SequenceContext

The context aggregates information about the sequence. It is passed the length of the sequence.

§

Struct

Represents a String->Field mapping.

Note: currently there is not a true map and only strings may be used as keys.

Fields

§fields: BTreeMap<String, Field>

Each String key gets assigned a Field. Currently we are using a BTreeMap, but that might change in the future.

§context: MapStructContext

The context aggregates information about the struct. It is passed a vector of the key names.

§

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")].

Fields

§variants: Vec<Schema>

A list of the possible schemas that were found.

Implementations§

Source§

impl Schema

Source

pub fn to_json_typegen_shape(&self) -> Shape

Convert a Schema to a json_typegen Shape.

Source

pub fn process_with_json_typegen( &self, mode: OutputMode, ) -> Result<String, JTError>

Convert a Schema to a supported json_typegen output

Source

pub fn process_with_json_typegen_options( &self, name: &str, options: &Options, ) -> Result<String, JTError>

Convert a Schema to a supported json_typegen output using custom settings.

Source§

impl Schema

Source

pub fn to_json_schema_with_schemars(&self) -> Result<String, impl Error>

Convert into a json_schema using the default settings.

Source

pub fn to_json_schema_with_schemars_version( &self, version: &JsonSchemaVersion, ) -> Result<String, impl Error>

Convert into a specific version of json_schema.

Source

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 Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Coalesce for Schema

Source§

fn coalesce(&mut self, other: Self)

Merge other into self.
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Schema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Schema> for Shape

Source§

fn from(schema: Schema) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Schema

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Schema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralEq for Schema

Source§

fn structural_eq(&self, other: &Self) -> bool

Returns true if self and other share the same structure.
Source§

fn structural_ne(&self, other: &Rhs) -> bool

Returns true if self and other DO NOT share the same structure.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CoalesceAny for T
where T: Coalesce + 'static,

Source§

fn coalesce_any(&mut self, other: Box<dyn Any>) -> Option<Box<dyn Any>>

Merge other into self. Trait object is returned if merging was unsuccessful.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,