Skip to main content

libxml/
lib.rs

1//! # A wrapper for libxml2
2//! This library provides an interface to a subset of the libxml API.
3//! The idea is to extend it whenever more functionality is needed.
4//! Providing a more or less complete wrapper would be too much work.
5#![deny(missing_docs)]
6// Our new methods return Result<Self, _> types
7#![allow(clippy::new_ret_no_self, clippy::result_unit_err)]
8/// Bindings to the C interface
9pub mod bindings;
10mod c_helpers;
11
12/// XML and HTML parsing
13pub mod parser;
14
15/// Manipulations on the DOM representation
16pub mod tree;
17
18/// XML Global Error Structures and Handling
19pub mod error;
20
21/// `XPath` module for global lookup in the DOM
22pub mod xpath;
23
24/// Schema Validation
25pub mod schemas;
26
27/// Read-only parallel primitives
28pub mod readonly;
29
30/// Ensure libxml2's global parser state is initialised. Safe to call from
31/// any number of threads — internally guarded by `std::sync::Once` so the
32/// underlying `xmlInitParser()` runs exactly once. Call this before
33/// performing any libxml2 operations from application code that does
34/// *not* go through the `parser::Parser` API (which initialises lazily).
35///
36/// See libxml2's own thread-safety guidance:
37/// <https://dev.w3.org/XInclude-Test-Suite/libxml2-2.4.24/doc/threads.html>
38pub fn init_parser() {
39  use std::sync::Once;
40  static INIT: Once = Once::new();
41  INIT.call_once(|| unsafe {
42    bindings::xmlInitParser();
43  });
44}