pub struct View { /* private fields */ }Expand description
A self-contained piece of HTML content.
A view may contain multiple sibling nodes, but opened tags must be closed so the fragment can be nested safely inside a larger document.
<!-- Valid: all tags are closed, safe to nest -->
<div>Hello</div>
<p>World</p>
<!-- Invalid: unclosed tag would corrupt the parent document -->
<div>HelloImplementations§
Source§impl View
impl View
Sourcepub const fn unescaped_unchecked(body: &'static str) -> Self
pub const fn unescaped_unchecked(body: &'static str) -> Self
Creates a view from a &'static str without escaping it and without checking for syntax
errors.
Sourcepub fn render(&self, cx: &Cx) -> String
pub fn render(&self, cx: &Cx) -> String
Renders the view into an HTML string.
Status codes and headers declared in the view are discarded;
render_response collects them.
Sourcepub fn render_response(&self, cx: &Cx) -> RenderedResponse
Available on crate feature http only.
pub fn render_response(&self, cx: &Cx) -> RenderedResponse
http only.Renders the view into HTML together with the status code and response headers declared in it.
A view declares response metadata by placing an
http::StatusCode, an http::HeaderMap,
or a single (HeaderName, HeaderValue) pair in the node position of
the view! macro. Competing declarations resolve by render order:
the first status code rendered wins, and the first part that mentions
a header name provides all of that name’s values.