leptris (Rust)
Idiomatic Rust bindings for libleptris — pure-C99 XML 1.0 parsing, a W3C-conformant XPath 1.0 engine, and SAX.
Linking
The crate links against a prebuilt libleptris shared library:
# Build the C library once (from the repository root):
# Then build/test the crate against it:
LEPTRIS_LIB_PATH=build-shared/src
LEPTRIS_LIB_PATH accepts the library file or its directory. Without
it the crate falls back to the system linker search (-lleptris).
Usage
use ;
let doc = parse?;
let root = doc.root.unwrap;
assert_eq!;
for book in root.children
let hits = doc.xpath?;
assert_eq!;
// Mixed nodesets (text, comments, attributes):
let nodes = doc.xpath?;
assert_eq!;
SAX with closures:
use sax;
let mut h = default;
h.start_element = Some;
h.characters = Some;
parse?;
Layout
Mirrors the Ruby (leptris-ruby) and Python (pyleptris) bindings:
a hand-maintained FFI layer (src/ffi.rs) mirroring the public
headers, with safe wrappers above it. The FFI drift gate keeps the
mirror in sync with the C surface.