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
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()); }
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
Auto Trait Implementations
impl RefUnwindSafe for Tag
impl UnwindSafe for Tag
Blanket Implementations
Mutably borrows from an owned value. Read more