pub struct Validator { /* private fields */ }Expand description
A rule set ready to validate documents: its schema loaded and its stylesheets
prepared, once. Validating a document only reads it, so one Validator serves any
number of documents, from any number of threads at once (Send + Sync); nothing of
the rule set is copied per document.
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn builtin(name: &str) -> Result<Self, Error>
pub fn builtin(name: &str) -> Result<Self, Error>
The built-in rule set name (see BUILTIN_RULE_SETS).
§Errors
Error::Bundle for an unknown name; otherwise as Validator::from_bundle,
which none of the built-in rule sets fails in practice (a test loads each).
Sourcepub fn cen_ubl() -> Result<Self, Error>
pub fn cen_ubl() -> Result<Self, Error>
The built-in rule set cen-ubl: the CEN EN 16931 validation artefacts for UBL,
release 1.3.17 (EUPL-1.2), embedded unmodified, with the UBL 2.1 schemas.
§Errors
None in practice (a test loads it); the error is returned rather than hidden.
Sourcepub fn from_bundle(
manifest: &str,
files: &[(&str, &[u8])],
) -> Result<Self, Error>
pub fn from_bundle( manifest: &str, files: &[(&str, &[u8])], ) -> Result<Self, Error>
Loads a bundle from memory: its manifest and its files, by their paths in the manifest. Files not named by the manifest are ignored.
§Errors
Error::Bundle for an invalid manifest, a missing file or a stylesheet that is
not well-formed; Error::Checksum for a file whose SHA-256 differs from the
manifest’s; Error::Unsupported for a stylesheet or schema outside the
supported subset.
Sourcepub fn from_bundle_dir(dir: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_bundle_dir(dir: impl AsRef<Path>) -> Result<Self, Error>
Loads the bundle in the directory dir: its manifest MANIFEST_FILE and the
files it names, relative to dir.
§Errors
Error::Io when a file cannot be read, otherwise as
Validator::from_bundle.
Sourcepub const fn rule_set(&self) -> &RuleSet
pub const fn rule_set(&self) -> &RuleSet
The rule set: name, version, schema, stylesheets and their checksums.
Sourcepub fn validate(&self, document: &[u8]) -> Result<Report, Error>
pub fn validate(&self, document: &[u8]) -> Result<Report, Error>
Validates a document with the default options (no document URI).
§Errors
Sourcepub fn validate_owned(&self, document: Vec<u8>) -> Result<Report, Error>
pub fn validate_owned(&self, document: Vec<u8>) -> Result<Report, Error>
Validates a document given as a buffer, with the default options (no document URI).
§Errors
Sourcepub fn validate_owned_with(
&self,
document: Vec<u8>,
options: &ValidateOptions<'_>,
) -> Result<Report, Error>
pub fn validate_owned_with( &self, document: Vec<u8>, options: &ValidateOptions<'_>, ) -> Result<Report, Error>
Validator::validate_with on a document given as a buffer, which the
validation keeps instead of copying: the buffer becomes the text without a copy,
and the tree of the last stylesheet refers to it, so that while that stylesheet
runs the document is in memory once rather than twice. Same report as
Validator::validate_with; for a caller that has no further use for the bytes
(a file just read).
§Errors
Sourcepub fn validate_with(
&self,
document: &[u8],
options: &ValidateOptions<'_>,
) -> Result<Report, Error>
pub fn validate_with( &self, document: &[u8], options: &ValidateOptions<'_>, ) -> Result<Report, Error>
Validates a document: checks that it is well-formed XML, validates it against
the rule set’s schema, then runs every stylesheet of the rule set on it. The
stylesheets run even when the schema reports errors, so that the report is
complete. When a stylesheet raises a dynamic error on a document that has schema
errors (a non-numeric amount the rules compute with, …), the report is returned
all the same, invalid, with the error in StylesheetReport::failure; without
schema errors, the error is returned.
The document must be UTF-8 (a byte order mark is allowed) and have no document type declaration.
§Errors
Error::NotXml when the document is not well-formed XML (or not UTF-8);
Error::Unsupported for another encoding, a document type declaration, or a
construct the engine refuses; Error::Transform when a stylesheet raises a
dynamic error on the document; Error::Bundle when a stylesheet’s result is
not an SVRL report; Error::Internal for a bug.