Expand description
The Next Rust view layer.
use next_rust_view::*;
fn card(title: &str) -> impl View {
div![class("card"), h2![title], p!["Escaped by default: <b>"]]
}
let html = render_static(card("Hello"));
assert_eq!(html, r#"<div class="card"><h2>Hello</h2><p>Escaped by default: <b></p></div>"#);Design:
- Element macros (
div!,p!, …) build anElementfrom a list of parts. A part is either an attribute (Attr) or a child view. - Everything that can be rendered implements
View, which converts it into aNodetree. Components are plain functions returningimpl View. - All text and attribute values are escaped. Raw HTML requires
raw_html, which is intentionally conspicuous. - Async content is expressed with
suspenseand can be streamed.
Re-exports§
pub use components::Children;pub use components::ImageProps;pub use components::LinkProps;pub use components::Slots;pub use components::each;pub use components::fragment_of;pub use components::island;pub use components::raw_html;pub use components::suspense;pub use components::when;pub use metadata::Metadata;pub use style::CssClass;pub use style::Stylesheet;pub use attrs::*;
Modules§
- attrs
- Attribute helpers.
- class_
names - Short class names for production builds.
- components
- Built-in components and composition helpers.
- metadata
- Document metadata (
<head>contents). - style
- Stylesheets created by the
css_module!andglobal_css!macros.
Macros§
- Image
- Responsive, lazily loaded image.
- Link
- Client-side-navigation aware link.
- a
<a>element.- abbr
<abbr>element.- address
<address>element.- area
<area>void element (children are ignored).- article
<article>element.- aside
<aside>element.- audio
<audio>element.- b
<b>element.- base
<base>void element (children are ignored).- blockquote
<blockquote>element.- body
<body>element.- br
<br>void element (children are ignored).- button
<button>element.- canvas
<canvas>element.- caption
<caption>element.- circle
<circle>element.- cite
<cite>element.- clip
Path <clipPath>element.- code
<code>element.- col
<col>void element (children are ignored).- colgroup
<colgroup>element.- datalist
<datalist>element.- dd
<dd>element.- defs
<defs>element.- del
<del>element.- details
<details>element.- dfn
<dfn>element.- dialog
<dialog>element.- div
<div>element.- dl
<dl>element.- dt
<dt>element.- ellipse
<ellipse>element.- em
<em>element.- embed
<embed>void element (children are ignored).- feBlend
<feBlend>element (SVG).- feColor
Matrix <feColorMatrix>element (SVG).- feComposite
<feComposite>element (SVG).- feDrop
Shadow <feDropShadow>element (SVG).- feFlood
<feFlood>element (SVG).- feGaussian
Blur <feGaussianBlur>element (SVG).- feMerge
<feMerge>element (SVG).- feMerge
Node <feMergeNode>element (SVG).- feOffset
<feOffset>element (SVG).- fieldset
<fieldset>element.- figcaption
<figcaption>element.- figure
<figure>element.- filter
<filter>element (SVG).- footer
<footer>element.- foreign
Object <foreignObject>element (SVG).- form
<form>element.- fragment
- Group children without a wrapper element:
fragment![a, b, c]. - g
<g>element.- h1
<h1>element.- h2
<h2>element.- h3
<h3>element.- h4
<h4>element.- h5
<h5>element.- h6
<h6>element.- head
<head>element.- header
<header>element.- hgroup
<hgroup>element.- hr
<hr>void element (children are ignored).- html
<html>element.- i
<i>element.- iframe
<iframe>element.- img
<img>void element (children are ignored).- input
<input>void element (children are ignored).- ins
<ins>element.- kbd
<kbd>element.- label
<label>element.- legend
<legend>element.- li
<li>element.- linear
Gradient <linearGradient>element.- link
<link>void element (children are ignored).- main
<main>element.- mark
<mark>element.- marker
<marker>element (SVG).- mask
<mask>element (SVG).- menu
<menu>element.- meta
<meta>void element (children are ignored).- meter
<meter>element.- nav
<nav>element.- noscript
<noscript>element.- object
<object>element.- ol
<ol>element.- optgroup
<optgroup>element.- option
<option>element.- output
<output>element.- p
<p>element.- path
<path>element.- pattern
<pattern>element (SVG).- picture
<picture>element.- polygon
<polygon>element.- polyline
<polyline>element.- pre
<pre>element.- progress
<progress>element.- q
<q>element.- radial
Gradient <radialGradient>element.- rect
<rect>element.- rp
<rp>element.- rt
<rt>element.- ruby
<ruby>element.- s
<s>element.- samp
<samp>element.- script
<script>element.- section
<section>element.- select
<select>element.- slot
<slot>element.- small
<small>element.- source
<source>void element (children are ignored).- span
<span>element.- stop
<stop>element.- strong
<strong>element.- style
<style>element.- sub
<sub>element.- summary
<summary>element.- sup
<sup>element.- svg
<svg>element.- symbol
<symbol>element.- table
<table>element.- tbody
<tbody>element.- td
<td>element.- template
<template>element.- text
<text>element (SVG).- text
Path <textPath>element (SVG).- textarea
<textarea>element.- tfoot
<tfoot>element.- th
<th>element.- thead
<thead>element.- time
<time>element.- title
<title>element.- tr
<tr>element.- track
<track>void element (children are ignored).- tspan
<tspan>element (SVG).- u
<u>element.- ul
<ul>element.- use_
<use>element.- var
<var>element.- video
<video>element.- wbr
<wbr>void element (children are ignored).
Structs§
- Attr
- An attribute. Create with the helpers in
crate::attrs. - Document
Parts - Everything needed to render a full HTML document.
- Element
- An HTML element.
- Render
Flags - Features used by a rendered document; the server uses these to decide which (if any) client scripts to include.
- Suspense
- An async boundary:
fallbackis rendered immediately,contentreplaces it once resolved (in place when not streaming, out-of-order when streaming).
Enums§
Constants§
- STREAMING_
RUNTIME - Inline script used to swap streamed content into place.
- TAGS
- Names of all generated element macros.
- VOID_
TAGS - Names of void elements.
Traits§
- Into
View Result - Conversion of a component’s return value into a render result: accepts
impl Viewas well asResult<impl View, E>. Used by generated code. - Part
- Something that can be placed inside an element macro.
- View
- Anything renderable.
Functions§
- escape_
attr - Escape attribute values (
&,<,>,",'). - escape_
text - Escape text content (
&,<,>). - is_
safe_ url - Whether a URL is safe to place in a URL attribute.
- render_
static - Render synchronously. Suspense boundaries render their fallback.
- render_
to_ string - Render to a string, awaiting all async content.
- resolve
- Resolve every suspense boundary in a tree (siblings concurrently).
- restyle_
document - Rewrite the per-class
<style>elements of a rendered document (a cached static page) for a browser that already has the style idsknown: only what it is missing is kept. Every per-class stylesheet rendered so far (component libraries’ too) is considered, besidessheets. - script_
key - The key of a script URL in
Stylesheet::scripts: the path under/_next-rust/orpublic/, without query string or fingerprint (/_next-rust/assets/js/site.1a2b3c4d5e6f7a8b.js→assets/js/site.js). - stream_
document - Render a complete document as a stream of chunks.