Struct Element

Source
pub struct Element<'a, T>
where T: ElementType,
{ pub name: Tag<'a>, pub attributes: Attributes<'a>, pub children: T, }
Expand description

The html element type. This is the most common Note: if children is None, then it is handled as an empty element, this is different than having no children

Fields§

§name: Tag<'a>§attributes: Attributes<'a>§children: T

Implementations§

Source§

impl<'a> Element<'a, ()>

Source

pub fn external_style(url: Url) -> Self

An external stylesheet (link tag)

Source§

impl<'a> Element<'a, Vec<Node<'a>>>

Source

pub fn push<N>(&mut self, node: N)
where N: Into<Node<'a>>,

Pushes a child not into the element Note: you can also do this yourself, but this is nicer as it will coerce anything that can be a node into a node

Examples found in repository?
examples/simple.rs (line 25)
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}
Source

pub fn anchor(url: Value<'a>, label: Text) -> Self

Helper function to create a link given the label and url

Examples found in repository?
examples/simple.rs (line 15)
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}
Source

pub fn body<N>(children: Vec<N>) -> Self
where N: Into<Node<'a>>,

Creates a body element. Note consumes the children vector

Examples found in repository?
examples/simple.rs (line 18)
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}
Source

pub fn html( lang: Value<'a>, header: Element<'a, Vec<Node<'a>>>, body: Element<'a, Vec<Node<'a>>>, ) -> Self

Creates the html element Helper here assumes you have a body and header. as thats’s used pretty much always

Examples found in repository?
examples/simple.rs (line 28)
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}
Source

pub fn title(title: Text) -> Self

Creates a html title, with the supplied text

Examples found in repository?
examples/simple.rs (line 24)
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}
Source

pub fn inline_script(text: Text) -> Self

Creates an inline script in to be used in the head section

Source

pub fn external_script(url: Url) -> Self

An external script tag

Source

pub fn inline_style(text: Text) -> Self

Creates an inline script in to be used in the head section

Source

pub fn head() -> Self

Creates the head section of a document

Source

pub fn main() -> Self

Creats a main, used to hold bulk of page

Source§

impl<'a, T> Element<'a, T>
where T: ElementType,

Source

pub fn create(name: Tag<'a>) -> Self

Creates a typical element with children, from the provided tag name. This is the typical case

Examples found in repository?
examples/simple.rs (line 22)
9fn main() {
10    // Create a link
11    let link = {
12        let label = Text::create("Click Me");
13        let url = Value::create("http://google.com").unwrap();
14        // Anchor is a helper for the typical case
15        Element::anchor(url, label)
16    };
17    // Create the body. Sugar function takes a list of child nodes
18    let body = Element::body(vec![link]);
19
20    // Create a header manually. There isn't a sugar function here
21    let header = {
22        let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23        let text = Text::create("Hello world");
24        let title = Element::title(text);
25        el.push(title);
26        el
27    };
28    let html = Element::html(Value::EN, header, body);
29
30    // Convert an element into a node
31    let node: Node = html.into();
32
33    // Nodes can be turned into HTML formatted strings
34    let string: String = node.into();
35
36    println!("{}", string);
37}
Source

pub fn set_bool_attribute(&mut self, key: Attribute<'a>)

Sets the supplied attribute as a ‘boolean’ attribute This means it will just appear in the html, and will not render with a =value eg

Source

pub fn has_bool_attribute(&self, key: &Attribute<'a>) -> bool

Tests whether the attribute exists. Note this returns true for bool attributes, and valued attributes

Source

pub fn has_attribute(&self, key: &Attribute<'a>) -> bool

Tests whether the attribute exists. Note this returns false for bool attributes, and true for valued attributes

Source

pub fn set_attribute(&mut self, key: Attribute<'a>, value: Value<'a>)

Sets the attribute to the supplied value Note: sugar over wrapping the value with some.

Source

pub fn get_attribute_value(&self, key: &Attribute<'a>) -> &Option<Value<'a>>

Returns the value of the supplied key note for bool attributes, this will still be none

Trait Implementations§

Source§

impl<'a, T> Clone for Element<'a, T>
where T: ElementType + Clone,

Source§

fn clone(&self) -> Element<'a, T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> From<Body> for Element<'a, Vec<Node<'a>>>

Source§

fn from(value: Body) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Element<'a, ()>> for Node<'a>

Source§

fn from(original: Element<'a, ()>) -> Node<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Element<'a, Vec<Node<'a>>>> for Node<'a>

Source§

fn from(original: Element<'a, Vec<Node<'a>>>) -> Node<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Head> for Element<'a, Vec<Node<'a>>>

Source§

fn from(value: Head) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Html> for Element<'a, Vec<Node<'a>>>

Source§

fn from(value: Html) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Element<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for Element<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Element<'a, T>
where T: Send,

§

impl<'a, T> Sync for Element<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Element<'a, T>
where T: Unpin,

§

impl<'a, T> UnwindSafe for Element<'a, T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.