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
impl Schema
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty schema. Add types with the builder methods, or use
crate::xsd::compile.
Sourcepub fn element(
&mut self,
name: impl Into<String>,
type_name: impl Into<String>,
) -> &mut Self
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.
Sourcepub fn simple(
&mut self,
name: impl Into<String>,
base: impl Into<String>,
) -> &mut Self
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.
Sourcepub fn simple_with(
&mut self,
name: impl Into<String>,
base: impl Into<String>,
facets: Facets,
) -> &mut Self
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.
Sourcepub fn complex(
&mut self,
name: impl Into<String>,
elements: Vec<Element>,
) -> &mut Self
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.
Sourcepub fn complex_groups(
&mut self,
name: impl Into<String>,
groups: Vec<Group>,
) -> &mut Self
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.
Sourcepub fn complex_abstract(
&mut self,
name: impl Into<String>,
elements: Vec<Element>,
) -> &mut Self
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.
Sourcepub fn extend(
&mut self,
name: impl Into<String>,
base: impl Into<String>,
extra: Vec<Element>,
) -> &mut Self
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.
Sourcepub fn global_type(&self, element: &str) -> Option<&str>
pub fn global_type(&self, element: &str) -> Option<&str>
Declared type of the global element element, if any.
Sourcepub fn flatten<'a>(
&'a self,
type_name: &str,
) -> Result<Vec<&'a Element>, UciError>
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.
Sourcepub fn groups<'a>(&'a self, type_name: &str) -> Result<Vec<&'a Group>, UciError>
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.
Sourcefn groups_chain<'a>(
&'a self,
type_name: &str,
chain: &mut Vec<String>,
) -> Result<Vec<&'a Group>, UciError>
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.
Sourcepub fn is_complex(&self, type_name: &str) -> bool
pub fn is_complex(&self, type_name: &str) -> bool
Whether type_name is a named complex type in this schema.
Sourcepub fn is_simple(&self, type_name: &str) -> bool
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.
Sourcepub fn primitive<'a>(&'a self, type_name: &'a str) -> &'a str
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.
Sourcepub fn effective_facets<'a>(&'a self, type_name: &str) -> Effective<'a>
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.
Sourcepub fn unchecked_primitives(&self) -> Vec<&str>
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.
Sourcepub fn unchecked_patterns(&self) -> Vec<(&str, &str)>
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.