pub trait Layout {
// Required method
fn wrap(&self, content: Node) -> Node;
// Provided method
fn wrap_many(&self, contents: Vec<Node>) -> Node { ... }
}Expand description
Wraps content in a consistent structure: a header, a footer, navigation.
§A footgun that does not exist here
A component is a value, not a shared handle. Node is a value type, so using one
instance in two places copies it and the copies cannot affect each other. Write components
however you like: a function, a struct, a constant.
§Examples
use molt::prelude::*;
use molt::Layout;
struct Blog { site_title: String }
impl Layout for Blog {
fn wrap(&self, content: Node) -> Node {
body()
.child(header().child(h1().text(&self.site_title)))
.child(main_tag().child(content))
.child(footer().child(p().text("© 2026")))
.into()
}
}
let page = Blog { site_title: "RideKeeper".into() }.wrap(p().text("Hello").into());
assert!(page.render().contains("<h1>RideKeeper</h1>"));Required Methods§
Provided Methods§
Sourcefn wrap_many(&self, contents: Vec<Node>) -> Node
fn wrap_many(&self, contents: Vec<Node>) -> Node
Wraps several nodes, grouping them in a <div> first.
Use Node::fragment and Layout::wrap if you would rather not have the wrapper.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".