Struct html_rs::elements::HtmlElement
source · pub struct HtmlElement<'a> {
pub tag: Tag<'a>,
pub children: Option<HtmlElementChildren<'a>>,
/* private fields */
}
Fields§
§tag: Tag<'a>
§children: Option<HtmlElementChildren<'a>>
Implementations§
source§impl<'a> HtmlElement<'a>
impl<'a> HtmlElement<'a>
pub fn builder(tag: Tag<'a>) -> HtmlElement<'a>
pub fn text<S: AsRef<str>>(self, text: S) -> HtmlElement<'a>
sourcepub fn attr<K: AsRef<str>, V: AsRef<str>>(
self,
key: K,
value: V,
) -> HtmlElement<'a>
pub fn attr<K: AsRef<str>, V: AsRef<str>>( self, key: K, value: V, ) -> HtmlElement<'a>
Examples found in repository?
examples/getting_started.rs (line 18)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
let title = HtmlHeadItem::new("<title>It works!</title>");
let style = HtmlStyle::new("body { color: #000000; }");
let script1 = HtmlScript::new(
format!(
r#"console.log("Hello from file {} at line {}")"#,
file!(),
line!(),
)
.as_str(),
);
let div = Div::builder().attr("class", "light-theme").append_child(
P::builder()
.attr("class", "light-theme")
.append_child(TextContent::text("It Works!")),
);
let body = HtmlBody::new().script(script1).append_child(div);
let script2 = HtmlScript::new(
format!(
r#"console.log("Hello from file {} at line {}")"#,
file!(),
line!(),
)
.as_str(),
);
let html = Html::new()
.head(title)
.add_style(style)
.add_script(script2)
.body(body);
#[cfg(feature = "debug")]
dbg!(&html);
println!("{html}");
}
sourcepub fn append_child(self, new_element: HtmlElement<'a>) -> HtmlElement<'a>
pub fn append_child(self, new_element: HtmlElement<'a>) -> HtmlElement<'a>
Examples found in repository?
examples/getting_started.rs (lines 18-22)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
let title = HtmlHeadItem::new("<title>It works!</title>");
let style = HtmlStyle::new("body { color: #000000; }");
let script1 = HtmlScript::new(
format!(
r#"console.log("Hello from file {} at line {}")"#,
file!(),
line!(),
)
.as_str(),
);
let div = Div::builder().attr("class", "light-theme").append_child(
P::builder()
.attr("class", "light-theme")
.append_child(TextContent::text("It Works!")),
);
let body = HtmlBody::new().script(script1).append_child(div);
let script2 = HtmlScript::new(
format!(
r#"console.log("Hello from file {} at line {}")"#,
file!(),
line!(),
)
.as_str(),
);
let html = Html::new()
.head(title)
.add_style(style)
.add_script(script2)
.body(body);
#[cfg(feature = "debug")]
dbg!(&html);
println!("{html}");
}
pub fn depth(&self) -> usize
pub fn set_depth(&mut self, depth: usize)
Trait Implementations§
source§impl<'a> Debug for HtmlElement<'a>
impl<'a> Debug for HtmlElement<'a>
source§impl Display for HtmlElement<'_>
impl Display for HtmlElement<'_>
source§impl PartialEq for HtmlElement<'_>
impl PartialEq for HtmlElement<'_>
impl Eq for HtmlElement<'_>
Auto Trait Implementations§
impl<'a> Freeze for HtmlElement<'a>
impl<'a> !RefUnwindSafe for HtmlElement<'a>
impl<'a> !Send for HtmlElement<'a>
impl<'a> !Sync for HtmlElement<'a>
impl<'a> Unpin for HtmlElement<'a>
impl<'a> !UnwindSafe for HtmlElement<'a>
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