Struct parsercher::dom::tag::Tag[][src]

pub struct Tag { /* fields omitted */ }
Expand description

A structure that represents a tag element. grammar: <[/]name [attr[="value"]] [/]>

Implementations

Create new Tag structer

Arguments

  • name - If <h1 class="section1">, then h1.

Returns the tag name. If <li class="item">, then li.

Set attributes.

Arguments

  • attr - Attribute name is key. Attribute value is value.

Examples

For <h1 id="title" class="section1">:

use std::collections::HashMap;
use parsercher::dom::Tag;

let mut tag = Tag::new("h1");
let mut attrs: HashMap<String, String> = HashMap::new();
attrs.insert("id".to_string(), "title".to_string());
attrs.insert("class".to_string(), "section1".to_string());
tag.set_attrs(attrs);

Returns attributes. If there is no attribute, None is returned.

Examples

For <h1 id="title" class="section1">:

use parsercher::dom::Tag;

let mut tag = Tag::new("h1");
tag.set_attr("id", "title");
tag.set_attr("class", "section1");

if let Some(attrs) = tag.get_attrs() {
    assert_eq!(attrs.get(&"id".to_string()), Some(&"title".to_string()));
    assert_eq!(attrs.get(&"class".to_string()), Some(&"section1".to_string()));
}

Set attribute.

Examples

For <h1 id="title" class="section1">:

use parsercher::dom::Tag;

let mut tag = Tag::new("h1");
tag.set_attr("id", "title");
tag.set_attr("class", "section1");

Returns the value of the specified attribute.

Examples

For <h1 id="title" class="section1">:

use parsercher::dom::Tag;

let mut tag = Tag::new("h1");
tag.set_attr("id", "title");
tag.set_attr("class", "section1");

if let Some(value) = tag.get_attr("class") {
    assert_eq!(value, "section1".to_string());
}

Set true to represent tags that are self-closed.

Examples

<area/>

Returns true if the self-closed tag.

Examples

<area/>

Set true to indicate that there is a terminator tag.

Examples

<h1></h1>

Returns true if there is a terminator tag.

Examples

<h1></h1>

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

Examples

use std::collections::HashMap;
use parsercher::dom::Tag;

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

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

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

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

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.