use std::sync::OnceLock;
use super::SchemaParserContext;
use crate::bindings;
use crate::error::StructuredError;
static SCHEMA_TYPES_LOCK: OnceLock<bool> = OnceLock::new();
pub struct Schema(*mut bindings::_xmlSchema);
impl Schema {
pub fn from_parser(parser: &mut SchemaParserContext) -> Result<Self, Vec<StructuredError>> {
let _ = SCHEMA_TYPES_LOCK.get_or_init(|| {
unsafe { bindings::xmlSchemaInitTypes() };
true
});
let raw = unsafe { bindings::xmlSchemaParse(parser.as_ptr()) };
if raw.is_null() {
Err(parser.drain_errors())
} else {
Ok(Self(raw))
}
}
pub fn as_ptr(&self) -> *mut bindings::_xmlSchema {
self.0
}
}
impl Drop for Schema {
fn drop(&mut self) {
unsafe { bindings::xmlSchemaFree(self.0) }
}
}