Skip to main content

Crate next_rust_view

Crate next_rust_view 

Source
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: &lt;b&gt;</p></div>"#);

Design:

  • Element macros (div!, p!, …) build an Element from 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 a Node tree. Components are plain functions returning impl View.
  • All text and attribute values are escaped. Raw HTML requires raw_html, which is intentionally conspicuous.
  • Async content is expressed with suspense and 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! and global_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.
clipPath
<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).
feColorMatrix
<feColorMatrix> element (SVG).
feComposite
<feComposite> element (SVG).
feDropShadow
<feDropShadow> element (SVG).
feFlood
<feFlood> element (SVG).
feGaussianBlur
<feGaussianBlur> element (SVG).
feMerge
<feMerge> element (SVG).
feMergeNode
<feMergeNode> element (SVG).
feOffset
<feOffset> element (SVG).
fieldset
<fieldset> element.
figcaption
<figcaption> element.
figure
<figure> element.
filter
<filter> element (SVG).
footer
<footer> element.
foreignObject
<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.
linearGradient
<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.
radialGradient
<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).
textPath
<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.
DocumentParts
Everything needed to render a full HTML document.
Element
An HTML element.
RenderFlags
Features used by a rendered document; the server uses these to decide which (if any) client scripts to include.
Suspense
An async boundary: fallback is rendered immediately, content replaces it once resolved (in place when not streaming, out-of-order when streaming).

Enums§

AttrValue
Attribute value.
Node
A rendered view tree.

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§

IntoViewResult
Conversion of a component’s return value into a render result: accepts impl View as well as Result<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 ids known: only what it is missing is kept. Every per-class stylesheet rendered so far (component libraries’ too) is considered, besides sheets.
script_key
The key of a script URL in Stylesheet::scripts: the path under /_next-rust/ or public/, 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.