oa_gateway_uci::schema

Struct Schema

Source
pub struct Schema {
    pub global_elements: HashMap<String, GlobalElement>,
    pub complex_types: HashMap<String, ComplexType>,
    pub simple_types: HashMap<String, SimpleType>,
}
Expand description

Enough of a UCI schema to convert and validate OMS JSON.

Not a full XSD infoset. Build one with the methods below, or compile the published catalog with crate::xsd::compile.

Fields§

§global_elements: HashMap<String, GlobalElement>§complex_types: HashMap<String, ComplexType>§simple_types: HashMap<String, SimpleType>

Named simple types: what each one restricts, and how. The target is usually an xs: primitive but may be another named simple type, so read it through Schema::primitive rather than directly, and read the constraints through Schema::effective_facets.

Implementations§

Source§

impl Schema

Source

pub fn new() -> Self

An empty schema. Add types with the builder methods, or use crate::xsd::compile.

Source

pub fn element( &mut self, name: impl Into<String>, type_name: impl Into<String>, ) -> &mut Self

Registers a global element named name of type type_name.

Source

pub fn simple( &mut self, name: impl Into<String>, base: impl Into<String>, ) -> &mut Self

Declare a named simple type that restricts base without narrowing it.

Source

pub fn simple_with( &mut self, name: impl Into<String>, base: impl Into<String>, facets: Facets, ) -> &mut Self

Declare a named simple type that restricts base with facets.

Source

pub fn complex( &mut self, name: impl Into<String>, elements: Vec<Element>, ) -> &mut Self

Declares a concrete type whose content is one sequence of elements.

Source

pub fn complex_groups( &mut self, name: impl Into<String>, groups: Vec<Group>, ) -> &mut Self

Declare a type from explicit compositors, for a choice or a mix of both.

Source

pub fn complex_abstract( &mut self, name: impl Into<String>, elements: Vec<Element>, ) -> &mut Self

Declares an abstract type. Instantiating it without $type / xsi:type is a validation error.

Source

pub fn extend( &mut self, name: impl Into<String>, base: impl Into<String>, extra: Vec<Element>, ) -> &mut Self

Declares name as an extension of base with extra fields.

Source

pub fn global_type(&self, element: &str) -> Option<&str>

Declared type of the global element element, if any.

Source

pub fn flatten<'a>( &'a self, type_name: &str, ) -> Result<Vec<&'a Element>, UciError>

Every element declaration a type contributes, base types included.

Errors on a cyclic extension chain rather than following it. Nothing in the published schema is cyclic, but a schema is an input like any other: it can come from a program-specific Message Set, and a chain that closes on itself would otherwise recurse until the stack ran out, at startup or on the first message that touched the type.

§Errors

Returns crate::UciError::Xsd on a cycle, or crate::UciError::UnknownType if type_name is not a complex type.

Source

pub fn groups<'a>(&'a self, type_name: &str) -> Result<Vec<&'a Group>, UciError>

The compositors a type is built from, base types first.

Self::flatten answers which elements may appear; this also answers under what compositor, which is what tells a set of optional siblings apart from a set of alternatives.

§Errors

Same as Self::flatten.

Source

fn groups_chain<'a>( &'a self, type_name: &str, chain: &mut Vec<String>, ) -> Result<Vec<&'a Group>, UciError>

Walks an extension chain, pushing names onto chain so a cycle can be named rather than followed.

Source

pub fn is_complex(&self, type_name: &str) -> bool

Whether type_name is a named complex type in this schema.

Source

pub fn is_simple(&self, type_name: &str) -> bool

Whether type_name holds a scalar value rather than child elements.

Covers both xs: primitives and the schema’s own named simple types — the published catalog defines over nine hundred of the latter, so a prefix test alone would misread them as complex.

Source

pub fn primitive<'a>(&'a self, type_name: &'a str) -> &'a str

Reduce type_name to the xs: primitive it ultimately restricts.

Leaf coercion matches on primitive names to decide whether a value is a JSON number, boolean, or string, so every named simple type has to be resolved through its restriction chain first. Returns type_name unchanged when it is already a primitive or is not a known simple type.

Source

pub fn effective_facets<'a>(&'a self, type_name: &str) -> Effective<'a>

Every constraint a value of type_name has to satisfy.

Walks the restriction chain, so a type that narrows another inherits what the other already required. An xs: primitive, or a type the schema does not define, constrains nothing.

Source

pub fn unchecked_primitives(&self) -> Vec<&str>

Every primitive in use that this build has no check for.

xs:string is left out: there is nothing to check about a string beyond the facets of the type declaring it. What appears here is a type whose values pass unexamined — xs:base64Binary, xs:anyURI, xs:QName — which is worth knowing when loading a schema this project has not seen.

Source

pub fn unchecked_patterns(&self) -> Vec<(&str, &str)>

Every pattern this build cannot check, paired with the type declaring it.

Empty for the published catalog. A program whose own schema uses a corner of XSD’s regex language that does not translate would see it here, which is the moment to know a constraint is going unread.

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

Source§

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

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

impl Default for Schema

Source§

fn default() -> Self

Same as Self::new.

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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.