pub trait NodeExtwhere
Self: Sized,{
Show 16 methods
// Required methods
fn children(&self) -> &RefCell<Vec<Node>>;
fn data(&self) -> &NodeData;
fn append_children(&self, children: Vec<Node>);
fn append_child(&self, child: Node);
// Provided methods
fn tag_name(&self) -> Option<String> { ... }
fn attr(self, name: &str, value: &str) -> Self { ... }
fn borrow_attr(&self, name: &str, value: &str) { ... }
fn attrs(self, attributes: Vec<(&str, &str)>) -> Self { ... }
fn borrow_attrs(&self, attributes: Vec<(&str, &str)>) { ... }
fn find_attribute(&self, attribute_name: &str) -> Option<usize> { ... }
fn attribute_eq(&self, attribute_name: &str, value: &str) -> bool { ... }
fn add_class(&self, class_value: &str) { ... }
fn remove_class(&self, class_value: &str) { ... }
fn has_class(&self, class_value: &str) -> bool { ... }
fn toggle_class(&self, class_value: &str) { ... }
fn remove_attribute(&self, name: &str) { ... }
}
Expand description
Methods for easy interaction with a DOM
Node.
Required Methods§
Sourcefn append_children(&self, children: Vec<Node>)
fn append_children(&self, children: Vec<Node>)
Appends the given children to the node.
Sourcefn append_child(&self, child: Node)
fn append_child(&self, child: Node)
Appends the given child to the node.
Provided Methods§
Sourcefn attr(self, name: &str, value: &str) -> Self
fn attr(self, name: &str, value: &str) -> Self
Adds an Attribute with given name and value to the node.
If the attribute is already present, it will be overridden.
Examples found in repository?
3fn main() {
4 let valid_html = document(
5 LanguageTag::parse("en-US").unwrap(),
6 head(vec![
7 link("text/css", "/static/css/main.css"),
8 ]),
9 body(vec![
10 h1(vec![text("Hello World!")]),
11 p(vec![text("This is the first paragraph created with lewp-html!")])
12 .attrs(vec![("class", "prelude"), ("id", "first-paragraph")]),
13 h2(vec![text("The elegant way to create HTML!")]),
14 p(vec![text("Creating HTML has never been easier. This paragraph is highlighted!")])
15 .attr("class", "highlighted"),
16 ]),
17 )
18 .into_html();
19 println!("{}", valid_html);
20}
Sourcefn borrow_attr(&self, name: &str, value: &str)
fn borrow_attr(&self, name: &str, value: &str)
Adds an Attribute with given name and value to the node without consuming self.
If the attribute is already present, it will be overridden.
Sourcefn attrs(self, attributes: Vec<(&str, &str)>) -> Self
fn attrs(self, attributes: Vec<(&str, &str)>) -> Self
Adds a list of attributes to the node.
The attributes are tuples of name and value. Attributes that are already set are being overridden.
Examples found in repository?
3fn main() {
4 let valid_html = document(
5 LanguageTag::parse("en-US").unwrap(),
6 head(vec![
7 link("text/css", "/static/css/main.css"),
8 ]),
9 body(vec![
10 h1(vec![text("Hello World!")]),
11 p(vec![text("This is the first paragraph created with lewp-html!")])
12 .attrs(vec![("class", "prelude"), ("id", "first-paragraph")]),
13 h2(vec![text("The elegant way to create HTML!")]),
14 p(vec![text("Creating HTML has never been easier. This paragraph is highlighted!")])
15 .attr("class", "highlighted"),
16 ]),
17 )
18 .into_html();
19 println!("{}", valid_html);
20}
Sourcefn borrow_attrs(&self, attributes: Vec<(&str, &str)>)
fn borrow_attrs(&self, attributes: Vec<(&str, &str)>)
Adds a list of attributes to the node without consuming self.
The attributes are tuples of name and value. Attributes that are already set are being overridden.
Sourcefn find_attribute(&self, attribute_name: &str) -> Option<usize>
fn find_attribute(&self, attribute_name: &str) -> Option<usize>
Returns the attribute index if present.
Sourcefn attribute_eq(&self, attribute_name: &str, value: &str) -> bool
fn attribute_eq(&self, attribute_name: &str, value: &str) -> bool
Checks if the given attribute matches the value.
Sourcefn add_class(&self, class_value: &str)
fn add_class(&self, class_value: &str)
Adds value
to the class
attribute. Adds the class
attribute if
it is not present.
Sourcefn remove_class(&self, class_value: &str)
fn remove_class(&self, class_value: &str)
Removes the given value
from the class
attribute.
Sourcefn toggle_class(&self, class_value: &str)
fn toggle_class(&self, class_value: &str)
Toggles the given value
of the class
attribute. Creates the class
attribute if not set yet.
Sourcefn remove_attribute(&self, name: &str)
fn remove_attribute(&self, name: &str)
Removes the attribute with the given name
. Does nothing
if the attribute does not exist. This method does not compare its
values.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.