pub struct Configuration { /* private fields */ }Expand description
The settings of one generated module.
Every setter returns the configuration, so that a build script can chain
them and end with process.
Implementations§
Source§impl Configuration
impl Configuration
Sourcepub fn new() -> Self
pub fn new() -> Self
A configuration with no schema yet, for XSD 1.0, covering every global element.
Sourcepub fn schema(&mut self, path: impl AsRef<Path>) -> &mut Self
pub fn schema(&mut self, path: impl AsRef<Path>) -> &mut Self
A schema document to compile, relative to the crate root (the
directory of Cargo.toml). Several documents are compiled into one
schema set; the documents they include and import are read too. Each
document is embedded under this path, or under the location the
documents name it by, resolved from here: its key.
A key is relative to the crate root, with / between its parts,
however the files are linked or placed; at run time the module’s
fallback finds the documents by their keys alone. A document outside
the crate root is keyed with .. from the crate root
(../shared/common.xsd), so its key spells the directories on the way
up, as far as the directory the crate root and the document share: a
crate outside the home directory whose schemas are inside it writes the
user’s name into the module and the binary. Keep the schemas inside the
crate, or link them in, to avoid that.
Sourcepub fn module(&mut self, name: impl Into<String>) -> &mut Self
pub fn module(&mut self, name: impl Into<String>) -> &mut Self
The module’s name: the generator writes $OUT_DIR/<name>.rs, and
include_validator!(<name>) declares it. Lower-case ASCII letters,
digits and _, starting with a letter or _, not a Rust keyword and
not a name Windows reserves for a device (con, nul, com1 …): a
file system that ignores case must not see two modules as one file.
Sourcepub fn root(&mut self, namespace: &str, local: &str) -> &mut Self
pub fn root(&mut self, namespace: &str, local: &str) -> &mut Self
Limit the tables to documents whose root is this global element
(namespace is "" for no namespace); may be given several times.
Without it, every global element is a possible root. A document with
another root is left to the dynamic validator.
Sourcepub fn xsd_version(&mut self, version: XsdVersion) -> &mut Self
pub fn xsd_version(&mut self, version: XsdVersion) -> &mut Self
The XSD version the schema is compiled as (default 1.0). An XSD 1.1
module needs the xsd11 feature on the dependency that includes it;
an XSD 1.0 module compiles with or without it.
Sourcepub fn map_location(&mut self, from: &str, to: impl AsRef<Path>) -> &mut Self
pub fn map_location(&mut self, from: &str, to: impl AsRef<Path>) -> &mut Self
Read the document at from (an absolute URI as a schema document
writes it, such as an http: URL) from the file to, relative to the
crate root, which must exist. The document is embedded under from,
and a relative location it names is read relative to to and
embedded relative to from.
Sourcepub fn emit_report(&mut self, on: bool) -> &mut Self
pub fn emit_report(&mut self, on: bool) -> &mut Self
Also write $OUT_DIR/<module>.report: the types, declarations and
value checks the tables do not cover, and why (a document that needs
one of them is left to the dynamic validator), and the pattern facets
without a table. The build prints a warning naming the file.
Sourcepub fn process(&self) -> Result<(), Box<dyn Error>>
pub fn process(&self) -> Result<(), Box<dyn Error>>
Compile the schema and write the module, from a build script (it
reads CARGO_MANIFEST_DIR and OUT_DIR). A schema that does not
compile, a remote location that is not mapped, or a root that is no
global element fails with a message that says which.