Struct Text

Source
pub struct Text(/* private fields */);
Expand description

The HTML text node. This is used inside tags eg

Text

Implementations§

Source§

impl Text

Source

pub fn create<S>(text: S) -> Text
where S: Into<String>,

Creates a text node. Note: will escape html markup eg <,>,&

Examples found in repository?
examples/semantic.rs (line 13)
12fn main() {
13    let title = Some(Text::create("Title"));
14    let styles = vec![];
15    let url = Url::absolute_unchecked("http://google.com".into());
16    let script = Script::External(url);
17    let scripts = vec![script];
18    let head = Head {
19        title,
20        styles,
21        scripts,
22    };
23    let content = vec![Text::create("Hello").into()];
24    let body = Body {
25        content,
26        scripts: vec![],
27        id: Some(Id::create("my-id").unwrap()),
28        class: vec![
29            Class::create("test").unwrap(),
30            Class::create("body").unwrap(),
31        ],
32    };
33    let html = Html {
34        head,
35        body,
36        lang: Value::EN,
37    };
38    let doc = Document { html };
39    let string: String = doc.into();
40
41    println!("{}", string);
42}
More examples
Hide additional examples
examples/simple.rs (line 12)
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}

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

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 Debug for Text

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<Text> for BodyElement

Source§

fn from(value: Text) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Text> for Node<'a>

Source§

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

Converts to this type from the input type.
Source§

impl From<Text> for String

Source§

fn from(original: Text) -> String

Converts to this type from the input type.
Source§

impl PartialEq for Text

Source§

fn eq(&self, other: &Text) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Text

Source§

impl StructuralPartialEq for Text

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

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.