| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
use std::sync::OnceLock; |
| 5 |
|
| 6 |
use super::SchemaParserContext; |
| 7 |
|
| 8 |
use crate::bindings; |
| 9 |
|
| 10 |
use crate::error::StructuredError; |
| 11 |
|
| 12 |
static SCHEMA_TYPES_LOCK: OnceLock<bool> = OnceLock::new(); |
| 13 |
|
| 14 |
|
| 15 |
pub struct Schema(*mut bindings::_xmlSchema); |
| 16 |
|
| 17 |
impl Schema { |
| 18 |
|
| 19 |
pub fn from_parser(parser: &mut SchemaParserContext) -> Result<Self, Vec<StructuredError>> { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
let _ = SCHEMA_TYPES_LOCK.get_or_init(|| { |
| 28 |
unsafe { bindings::xmlSchemaInitTypes() }; |
| 29 |
true |
| 30 |
}); |
| 31 |
|
| 32 |
let raw = unsafe { bindings::xmlSchemaParse(parser.as_ptr()) }; |
| 33 |
|
| 34 |
if raw.is_null() { |
| 35 |
Err(parser.drain_errors()) |
| 36 |
} else { |
| 37 |
Ok(Self(raw)) |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
pub fn as_ptr(&self) -> *mut bindings::_xmlSchema { |
| 43 |
self.0 |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
impl Drop for Schema { |
| 48 |
fn drop(&mut self) { |
| 49 |
unsafe { bindings::xmlSchemaFree(self.0) } |
| 50 |
} |
| 51 |
} |