1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*!
This module implements certain capabilities required by, but not specified by, the DOM Core.
*/
use crate::level2::node_impl::RefNode;
use crate::level2::traits::DOMImplementation;

// ------------------------------------------------------------------------------------------------
// Public Types
// ------------------------------------------------------------------------------------------------

#[doc(hidden)]
#[derive(Clone, Debug)]
pub(crate) struct Implementation {}

// ------------------------------------------------------------------------------------------------
// Public Functions
// ------------------------------------------------------------------------------------------------

const THIS_IMPLEMENTATION: &'static dyn DOMImplementation<NodeRef = RefNode> = &Implementation {};

///
/// Return a reference to an instance of this `DOMImplementation` implementation.
///
/// This function gets around the DOM bootstrap issue, the `implementation` method on the
/// [`Document`](trait.Document.html) trait requires an instance of `Document`; however, the
/// `create_document` method on `DOMImplementation` requires an instance from `implementation`.
///
/// # Example
///
/// ```rust
/// use xml_dom::level2::get_implementation;
///
/// let implementation = get_implementation();
/// let mut document_node = implementation
///     .create_document(Some("http://www.w3.org/1999/xhtml"), Some("html"), None)
///     .unwrap();
/// ```
///
pub fn get_implementation() -> &'static dyn DOMImplementation<NodeRef = RefNode> {
    THIS_IMPLEMENTATION
}

// ------------------------------------------------------------------------------------------------

const CRATE_NAME: &str = env!("CARGO_PKG_NAME");

const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");

///
/// Return a string with the vendor/version of the implementation.
///
pub fn get_implementation_version() -> String {
    format!("{}:{}", CRATE_NAME, CRATE_VERSION)
}