pub mod doc_type;
pub mod document;
pub mod element;
pub mod macros;
pub use doc_type::DomDocType;
pub use document::DomDocument;
pub use element::{DomElem, DomEmptyElem};
pub use macros::*;
pub trait Render {
fn render(&self) -> String;
}
#[derive(Debug, Clone)]
pub enum DomNode {
Document(DomDocument),
DocumentType(DomDocType),
EmptyElement(DomEmptyElem),
Element(DomElem),
Text(String),
}
pub use DomNode::*;
impl Render for DomNode {
fn render(&self) -> String {
match self {
Document(n) => n.render(),
DocumentType(n) => n.render(),
EmptyElement(n) => n.render(),
Element(n) => n.render(),
Text(n) => n.clone(),
}
}
}
impl DomNode {
pub fn as_doc(&self) -> Option<&DomDocument> {
match *self {
Document(ref e) => Some(e),
_ => None,
}
}
pub fn as_doc_mut(&mut self) -> Option<&mut DomDocument> {
match *self {
Document(ref mut e) => Some(e),
_ => None,
}
}
pub fn as_doctype(&self) -> Option<&DomDocType> {
match *self {
DocumentType(ref e) => Some(e),
_ => None,
}
}
pub fn as_doctype_mut(&mut self) -> Option<&mut DomDocType> {
match *self {
DocumentType(ref mut e) => Some(e),
_ => None,
}
}
pub fn as_empty(&self) -> Option<&DomEmptyElem> {
match *self {
EmptyElement(ref e) => Some(e),
_ => None,
}
}
pub fn as_empty_mut(&mut self) -> Option<&mut DomEmptyElem> {
match *self {
EmptyElement(ref mut e) => Some(e),
_ => None,
}
}
pub fn as_elem(&self) -> Option<&DomElem> {
match *self {
Element(ref e) => Some(e),
_ => None,
}
}
pub fn as_elem_mut(&mut self) -> Option<&mut DomElem> {
match *self {
Element(ref mut e) => Some(e),
_ => None,
}
}
pub fn as_text(&self) -> Option<&String> {
match *self {
Text(ref e) => Some(e),
_ => None,
}
}
pub fn as_text_mut(&mut self) -> Option<&mut String> {
match *self {
Text(ref mut e) => Some(e),
_ => None,
}
}
}