Skip to main content

Loader

Trait Loader 

Source
pub trait Loader {
    // Required method
    fn load(&self, href: &str, base: Option<&str>) -> Result<String, XsltError>;

    // Provided methods
    fn load_parsed(
        &self,
        href: &str,
        base: Option<&str>,
    ) -> Result<Arc<Document>, XsltError> { ... }
    fn resolve(
        &self,
        href: &str,
        base: Option<&str>,
    ) -> Result<String, XsltError> { ... }
    fn enumerate(&self, base: Option<&str>) -> Vec<String> { ... }
}
Expand description

Resolve a stylesheet / document reference to its source text.

href is the user-supplied URI from the stylesheet (e.g. the href= attribute of xsl:import). base is the URI of the containing stylesheet — used to resolve relative hrefs. Both follow XML URI handling conventions (RFC 3986 reference resolution); we keep them as opaque strings here so loaders can choose their own scheme.

Required Methods§

Source

fn load(&self, href: &str, base: Option<&str>) -> Result<String, XsltError>

Load href’s contents. Returns the raw source as a UTF-8 string. Implementations should resolve href against base when href is relative.

Provided Methods§

Source

fn load_parsed( &self, href: &str, base: Option<&str>, ) -> Result<Arc<Document>, XsltError>

Load href’s contents and return them as a parsed sup_xml_tree::dom::Document. Default implementation calls Self::load and parses fresh each time; loaders that expect repeated lookups for the same URI (filesystem, in-memory) should override to cache the parse result internally so the runtime doc() path doesn’t re-parse the same XML thousands of times across an apply sweep.

Returns an Arc so cache hits share the underlying document without cloning the arena.

Source

fn resolve(&self, href: &str, base: Option<&str>) -> Result<String, XsltError>

Compute the base URI to use for files imported FROM the resource at href. Default: returns href itself (used as the base for the next level of resolution).

Source

fn enumerate(&self, base: Option<&str>) -> Vec<String>

Enumerate every URI the loader can serve. Returned as hrefs that, when passed to Self::load with the same base, succeed. Called by the XSLT runtime when the stylesheet uses a dynamic document() / doc() URI (computed via concat / variables / @attr) — every enumerated URI is speculatively pre-loaded so that the runtime call can resolve against the pre-loaded map.

Default: empty. Loaders that can’t safely enumerate (HTTP / arbitrary URI schemes / sandboxed environments) leave it unimplemented, in which case stylesheets that build URIs dynamically fall back to “URI not pre-loaded” errors at runtime for any URI the static analysis missed.

Implementations should respect the same security boundary as load — e.g. FilesystemLoader::enumerate lists files under allowed_roots only.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§