Skip to main content

Validator

Struct Validator 

Source
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

Source

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

Source

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.

Source

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.

Source

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.

Source

pub const fn rule_set(&self) -> &RuleSet

The rule set: name, version, schema, stylesheets and their checksums.

Source

pub fn validate(&self, document: &[u8]) -> Result<Report, Error>

Validates a document with the default options (no document URI).

§Errors

As Validator::validate_with.

Source

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

As Validator::validate_with.

Source

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

As Validator::validate_with.

Source

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.

Trait Implementations§

Source§

impl Debug for Validator

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.