Skip to main content

SemanticElement

Trait SemanticElement 

Source
pub trait SemanticElement {
    // Required method
    fn build(&self) -> String;
}
Expand description

Trait implemented by all semantic element builders.

Each of Article, Section, Nav, and Aside expose the same fluent setters via a shared macro implementation; this trait is the polymorphic seam used when callers want to render any of them through a single API.

§Examples

use html_generator::elements::{Article, SemanticElement};

fn render<E: SemanticElement>(e: &E) -> String {
    e.build()
}

let html = render(&Article::new().id("a").child("<p>x</p>"));
assert!(html.contains("<article"));

Required Methods§

Source

fn build(&self) -> String

Render the element to an HTML string.

§Examples
use html_generator::elements::{Section, SemanticElement};

let html = Section::new().child("<h2>Hi</h2>").build();
assert!(html.contains("<section"));

Implementors§