Node

Struct Node 

Source
pub struct Node { /* private fields */ }
Expand description

A mutable struct composed of a tag, attribute list, child list and closing type.

Do not attempt to modify the Node element directly. Use the available methods.

Node {
    tag: String,
    attributes: Option<Vec<String>>,
    children: Option<Vec<Children>>,
    closing_type: Closing
}

Implementations§

Source§

impl Node

Source

pub fn set_attribute(&mut self, name: &str, value: &str)

Sets the value of the Node’s attribute. This does not return an error if the wrong (key, value) was set.

§Example
use aurochs::Document;
 
let mut html = Document::create_element("html");
html.set_attribute("lang", "en");
§Javascript Equivalent

MDN web docs

let html = document.createElement("html");
html.setAttribute("lang", "en");
§HTML
<html lang="en"></html>
Source

pub fn set_attribute_list(&mut self, attributes: Vec<(&str, &str)>)

Sets the values of the Node’s attributes. This does not return an error if the wrong (key, value) was set.

§Example
use aurochs::Document;
 
let mut script = Document::create_element("script");
script.set_attribute_list(vec![("src", "./main.js"), ("defer", ""), ("type", "module")]);
§Javascript Equivalent
let script = document.createElement("script");
const attributes = { "src": "./main.js", "defer": "", "type": "module" };
for (let key in attributes ) {
    script.setAttribute(key, attributes[key]);
}
§HTML
<script src="./main.js" defer type="module"></script>
Source

pub fn inner_text(&mut self, value: &str)

Sets the rendered text content of a Node.

§Example
use aurochs::Document;
 
let mut paragraph = Document::create_element("p");
paragraph.inner_text("Hello World!");
§Javascript Equivalent

MDN web docs

let paragraph = document.createElement("p");
paragraph.inner_text("Hello World!");
§HTML
<p>Hello World!</p>
Source

pub fn append_child(&mut self, node: Node)

Adds a Node to the end of the list of children of a specified parent Node.

§Example
use aurochs::Document;
 
let mut body = Document::create_element("body");
let mut paragraph = Document::create_element("p");
body.append_child(paragraph);
§Javascript Equivalent

MDN web docs

let body = document.createElement("body");
let paragraph = document.createElement("p");
body.appendChild(paragraph);
§HTML
<body>
    <p><p>
</body>
Source

pub fn append_child_list(&mut self, children: Vec<Node>)

Adds multiple Nodes to the end of the list of children of a specified parent Node.

§Example
use aurochs::Document;
 
let mut body = Document::create_element("body");
let mut h1 = Document::create_element("h1");
let mut h2 = Document::create_element("h2");
let mut h3 = Document::create_element("h3");
body.append_child_list(vec![ h1, h2, h3 ]);
§Javascript Equivalent
let body = document.createElement("body");
let h1 = document.createElement("h1");
let h2 = document.createElement("h2");
let h3 = document.createElement("h3");
 
const elements = { h1, h2, h3 };

for (let elem in elements) {
    body.appendChild(elements[elem]);
}
§HTML
<body>
    <h1><h1>
    <h2><h2>
    <h3><h3>
</body>
Source

pub fn clone_node(&self) -> Node

Returns a duplicate of the Node on which this method was called. Cloning a Node copies all of its attributes and their values, including intrinsic (inline) listeners.

Warning: clone_node() may lead to duplicate Node attributes in a document, such as IDs and CLASSes!

§Example
use aurochs::Document;
 
let mut paragraph = Document::create_element("p");
let mut paragraph_clone = paragraph.clone_node();
§Javascript Equivalent

MDN web docs

let paragraph = document.createElement("p");
let paragraph_clone = paragraph.cloneNode(true);
§HTML
<p><p>
<p><p>
Source

pub fn render(&self) -> String

Returns the parsed Node Tree as a string

§Example
use aurochs::Document;
 
let mut html = Document::create_element("html");
html.set_attribute("lang", "en");

let mut head = Document::create_element("head");
let mut body = Document::create_element("body");
 
html.append_child_list(vec![ head, body]);
 
println!("{}", html.render());
§HTML
<html lang="en">
    <head></head>
    <body></body>
</html>

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.