weft-xml 0.2.1

XPath 3.1, XQuery 3.1 and XSLT 3.0 in Rust: a command and the libraries under it, tested on the W3C suites
//! docs/usage.md's query example (crates/xml/tests/docs.rs holds the two to
//! one text): an XQuery, or an XPath expression, over a document's text.
//!
//!     cargo run -p weft-xml --example query

use xpath_ir::ctx::DocSource;
use xpath_ir::xquery::run_main_module;

/// What doc() and unparsed-text() may read: here, nothing.
struct NoDocuments;
impl DocSource for NoDocuments {
    fn path_of(&self, _uri: &str) -> Option<String> {
        None
    }
    fn bytes(&self, _path: &str) -> Option<&[u8]> {
        None
    }
    fn uri_of(&self, path: &str) -> String {
        path.to_string()
    }
}

fn main() {
    let document = ("<d><i n='1'/><i n='2'/></d>", "file:///d.xml"); // its text and its URI
    match run_main_module("sum(//@n) + 1", "file:///query.xq", Some(document), &NoDocuments) {
        Ok(result) => println!("{result}"),
        Err(error) => eprintln!("{error}"), // the W3C error code, then a message
    }
}