Skip to main content

xsd_schema/document/
mod.rs

1//! Page-based XML document buffer for XPath 2.0 evaluation.
2//!
3//! This module implements `BufferDocument`, a compact, cache-friendly XML document
4//! representation built on a flat array of 16-byte [`Node`] structs with power-of-2
5//! page addressing.
6//!
7//! # Feature gate
8//!
9//! The entire module is compiled only when the `xsd11` feature is enabled.
10
11pub mod buffer;
12pub mod builder;
13pub mod element_index;
14pub mod error;
15pub mod namespace;
16pub mod navigator;
17pub mod node;
18pub mod page;
19pub mod qname;
20pub mod source_spans;
21pub mod strings;
22pub mod type_remap;
23pub mod typed_builder;
24
25pub use buffer::BufferDocument;
26pub use builder::BufferDocumentBuilder;
27pub use element_index::ElementIndex;
28pub use error::BufferDocumentError;
29pub use namespace::{
30    NamespaceChain, NamespaceNode, NamespacePageFactory, NsRef, NS_PAGE_MASK, NS_PAGE_SHIFT,
31    NS_PAGE_SIZE,
32};
33pub use navigator::BufferDocNavigator;
34pub use node::{
35    node_ref_from, page_of, slot_of, Node, NodeType, NULL, PAGE_MASK, PAGE_SHIFT, PAGE_SIZE,
36};
37pub use page::NodePages;
38pub use qname::{QNameAtom, QNameTable, EMPTY_QNAME};
39pub use source_spans::NodeSourceSpans;
40pub use strings::StringStore;
41pub use type_remap::{BindingRemapTable, NodeSchemaBinding};
42pub use typed_builder::{build_typed_document, SilentValidationSink};
43
44/// Whether the document is a complete XML document or a validation fragment.
45#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
46pub enum DocumentKind {
47    /// Complete XML document (default).
48    #[default]
49    Full,
50    /// Assertion-evaluation fragment (synthetic root wrapping a single element).
51    Fragment,
52}
53
54/// Configuration for [`BufferDocument`] construction.
55#[derive(Clone, Copy, Debug, PartialEq, Eq)]
56pub struct BufferDocumentOptions {
57    /// Document mode.
58    pub kind: DocumentKind,
59    /// Whether to record source byte-offsets per node.
60    pub track_source_locations: bool,
61}
62
63impl Default for BufferDocumentOptions {
64    fn default() -> Self {
65        Self {
66            kind: DocumentKind::Full,
67            track_source_locations: false,
68        }
69    }
70}
71
72impl BufferDocumentOptions {
73    /// Full-document mode with source location tracking enabled.
74    pub fn full() -> Self {
75        Self {
76            kind: DocumentKind::Full,
77            track_source_locations: true,
78        }
79    }
80
81    /// Fragment mode with source location tracking disabled.
82    pub fn fragment() -> Self {
83        Self {
84            kind: DocumentKind::Fragment,
85            track_source_locations: false,
86        }
87    }
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93
94    #[test]
95    fn document_kind_default_is_full() {
96        assert_eq!(DocumentKind::default(), DocumentKind::Full);
97    }
98
99    #[test]
100    fn options_default() {
101        let opts = BufferDocumentOptions::default();
102        assert_eq!(opts.kind, DocumentKind::Full);
103        assert!(!opts.track_source_locations);
104    }
105
106    #[test]
107    fn options_full() {
108        let opts = BufferDocumentOptions::full();
109        assert_eq!(opts.kind, DocumentKind::Full);
110        assert!(opts.track_source_locations);
111    }
112
113    #[test]
114    fn options_fragment() {
115        let opts = BufferDocumentOptions::fragment();
116        assert_eq!(opts.kind, DocumentKind::Fragment);
117        assert!(!opts.track_source_locations);
118    }
119}