pub struct Text(/* private fields */);
Expand description
The HTML text node. This is used inside tags eg
Text
Implementations§
Source§impl Text
impl Text
Sourcepub fn create<S>(text: S) -> Text
pub fn create<S>(text: S) -> Text
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
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<'a> From<Text> for BodyElement
impl<'a> From<Text> for BodyElement
impl Eq for Text
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more