Struct parsercher::dom::Dom[][src]

pub struct Dom {
    pub dom_type: DomType,
    // some fields omitted
}
Expand description

A structure that represents the parsing result of a tag document.

Fields

dom_type: DomType
Expand description

Type of Dom structure

Implementations

impl Dom[src]

pub fn new(dom_type: DomType) -> Dom[src]

Create new Dom structure.

pub fn new_root() -> Dom[src]

Create the new root dom.

The root dom has a Tag structure whose name is root.

pub fn set_tag(&mut self, tag: Tag)[src]

Set Tag structure.

Panics

self.dom_type is not DomType::Tag

pub fn get_tag(&self) -> Option<&Tag>[src]

Returns the Tag structure. If it does not have a Tag structure, it returns None.

pub fn set_text(&mut self, text: Text)[src]

Set Text structure.

Panics

self.dom_type is not DomType::Text

pub fn get_text(&self) -> Option<&Text>[src]

Returns the Text structure. If it does not have a Text structure, it returns None.

pub fn set_comment(&mut self, comment: Comment)[src]

Set Comment structure.

Panics

self.dom_type is not DomType::Comment

pub fn get_comment(&self) -> Option<&Comment>[src]

Returns the Comment structure. If it does not have a Comment structure, it returns None.

pub fn add_child(&mut self, dom: Dom)[src]

Add a child Dom structure.

pub fn get_children(&self) -> Option<&Vec<Box<Dom>>>[src]

Returns child Dom structures as Vec. If it does not have children, it returns None.

pub fn p_implies_q(p: &Dom, q: &Dom) -> bool[src]

Returns true if p is a sufficient condition for q. p => q

Examples

use parsercher::dom::DomType;
use parsercher::dom::Dom;
use parsercher::dom::Tag;

let mut p = Dom::new(DomType::Tag);
let mut tag = Tag::new("h1");
tag.set_attr("class", "target");
p.set_tag(tag);

let mut q = Dom::new(DomType::Tag);
let mut tag = Tag::new("h1");
tag.set_attr("id", "q");
tag.set_attr("class", "target");
q.set_tag(tag);

assert_eq!(Dom::p_implies_q(&p, &q), true);

let mut q = Dom::new(DomType::Tag);
let mut tag = Tag::new("h1");
tag.set_attr("id", "q");
q.set_tag(tag);

assert_eq!(Dom::p_implies_q(&p, &q), false);

pub fn p_implies_q_tree(p: &Dom, q: &Dom) -> bool[src]

Returns true if p is a sufficient condition for q. Compare the entire tree. p => q

Examples

use parsercher;
use parsercher::dom::Dom;

// p
let p = r#"
<h1>
  <div></div>
  <ul>
    <li></li>
  </ul>
</h1>
"#;

let p_dom = parsercher::parse(&p).unwrap();
// Remove `root`dom of p_dom
let p_dom = p_dom.get_children().unwrap().get(0).unwrap();

// q
let q = r#"
<h1>
  <div id="divId"></div>
  <ul>
    <li></li>
  </ul>
  <span></span>
</h1>
"#;

let q_dom = parsercher::parse(&q).unwrap();
// Remove `root`dom of p_dom
let q_dom = q_dom.get_children().unwrap().get(0).unwrap();

assert_eq!(Dom::p_implies_q_tree(&p_dom, &q_dom), true);

Trait Implementations

impl Clone for Dom[src]

fn clone(&self) -> Dom[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Dom[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl PartialEq<Dom> for Dom[src]

fn eq(&self, other: &Dom) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Dom) -> bool[src]

This method tests for !=.

impl StructuralPartialEq for Dom[src]

Auto Trait Implementations

impl RefUnwindSafe for Dom

impl Send for Dom

impl Sync for Dom

impl Unpin for Dom

impl UnwindSafe for Dom

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.