pub trait RenderHtml:
Render
+ AddAnyAttr
+ Send {
type AsyncOutput: RenderHtml;
type Owned: RenderHtml + 'static;
const MIN_LENGTH: usize;
const EXISTS: bool = true;
Show 16 methods
// Required methods
fn dry_resolve(&mut self);
fn resolve(self) -> impl Future<Output = Self::AsyncOutput> + Send;
fn to_html_with_buf(
self,
buf: &mut String,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
);
fn hydrate<const FROM_SERVER: bool>(
self,
cursor: &Cursor,
position: &PositionState,
) -> Self::State;
fn into_owned(self) -> Self::Owned;
// Provided methods
fn html_len(&self) -> usize { ... }
fn to_html(self) -> String
where Self: Sized { ... }
fn to_html_branching(self) -> String
where Self: Sized { ... }
fn to_html_stream_in_order(self) -> StreamBuilder
where Self: Sized { ... }
fn to_html_stream_in_order_branching(self) -> StreamBuilder
where Self: Sized { ... }
fn to_html_stream_out_of_order(self) -> StreamBuilder
where Self: Sized { ... }
fn to_html_stream_out_of_order_branching(self) -> StreamBuilder
where Self: Sized { ... }
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
self,
buf: &mut StreamBuilder,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
)
where Self: Sized { ... }
fn hydrate_async(
self,
cursor: &Cursor,
position: &PositionState,
) -> impl Future<Output = Self::State> { ... }
fn hydrate_from<const FROM_SERVER: bool>(self, el: &Element) -> Self::State
where Self: Sized { ... }
fn hydrate_from_position<const FROM_SERVER: bool>(
self,
el: &Element,
position: Position,
) -> Self::State
where Self: Sized { ... }
}Expand description
The RenderHtml trait allows rendering something to HTML, and transforming
that HTML into an interactive interface.
This process is traditionally called “server rendering” and “hydration.” As a metaphor, this means that the structure of the view is created on the server, then “dehydrated” to HTML, sent across the network, and “rehydrated” with interactivity in the browser.
However, the same process can be done entirely in the browser: for example, a view
can be transformed into some HTML that is used to create a <template> node, which
can be cloned many times and “hydrated,” which is more efficient than creating the
whole view piece by piece.
Required Associated Constants§
Sourceconst MIN_LENGTH: usize
const MIN_LENGTH: usize
The minimum length of HTML created when this view is rendered.
Provided Associated Constants§
Required Associated Types§
Sourcetype AsyncOutput: RenderHtml
type AsyncOutput: RenderHtml
The type of the view after waiting for all asynchronous data to load.
Sourcetype Owned: RenderHtml + 'static
type Owned: RenderHtml + 'static
An equivalent value that is 'static.
Required Methods§
Sourcefn dry_resolve(&mut self)
fn dry_resolve(&mut self)
“Runs” the view without other side effects. For primitive types, this is a no-op. For reactive types, this can be used to gather data about reactivity or about asynchronous data that needs to be loaded.
Sourcefn resolve(self) -> impl Future<Output = Self::AsyncOutput> + Send
fn resolve(self) -> impl Future<Output = Self::AsyncOutput> + Send
Waits for any asynchronous sections of the view to load and returns the output.
Sourcefn to_html_with_buf(
self,
buf: &mut String,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
)
fn to_html_with_buf( self, buf: &mut String, position: &mut Position, escape: bool, mark_branches: bool, extra_attrs: Vec<AnyAttribute>, )
Renders a view to HTML, writing it into the given buffer.
Sourcefn hydrate<const FROM_SERVER: bool>(
self,
cursor: &Cursor,
position: &PositionState,
) -> Self::State
fn hydrate<const FROM_SERVER: bool>( self, cursor: &Cursor, position: &PositionState, ) -> Self::State
Makes a set of DOM nodes rendered from HTML interactive.
If FROM_SERVER is true, this HTML was rendered using RenderHtml::to_html
(e.g., during server-side rendering ).
If FROM_SERVER is false, the HTML was rendered using ToTemplate::to_template
(e.g., into a <template> element).
Sourcefn into_owned(self) -> Self::Owned
fn into_owned(self) -> Self::Owned
Convert into the equivalent value that is 'static.
Provided Methods§
Sourcefn html_len(&self) -> usize
fn html_len(&self) -> usize
An estimated length for this view, when rendered to HTML.
This is used for calculating the string buffer size when rendering HTML. It does not need to be precise, but should be an appropriate estimate. The more accurate, the fewer reallocations will be required and the faster server-side rendering will be.
Sourcefn to_html_branching(self) -> Stringwhere
Self: Sized,
fn to_html_branching(self) -> Stringwhere
Self: Sized,
Renders a view to HTML with branch markers. This can be used to support libraries that diff HTML pages against one another, by marking sections of the view that branch to different types with marker comments.
Sourcefn to_html_stream_in_order(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_in_order(self) -> StreamBuilderwhere
Self: Sized,
Renders a view to an in-order stream of HTML.
Sourcefn to_html_stream_in_order_branching(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_in_order_branching(self) -> StreamBuilderwhere
Self: Sized,
Renders a view to an in-order stream of HTML with branch markers. This can be used to support libraries that diff HTML pages against one another, by marking sections of the view that branch to different types with marker comments.
Sourcefn to_html_stream_out_of_order(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_out_of_order(self) -> StreamBuilderwhere
Self: Sized,
Renders a view to an out-of-order stream of HTML.
Sourcefn to_html_stream_out_of_order_branching(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_out_of_order_branching(self) -> StreamBuilderwhere
Self: Sized,
Renders a view to an out-of-order stream of HTML with branch markers. This can be used to support libraries that diff HTML pages against one another, by marking sections of the view that branch to different types with marker comments.
Sourcefn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
self,
buf: &mut StreamBuilder,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
)where
Self: Sized,
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
self,
buf: &mut StreamBuilder,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
)where
Self: Sized,
Renders a view into a buffer of (synchronous or asynchronous) HTML chunks.
Sourcefn hydrate_async(
self,
cursor: &Cursor,
position: &PositionState,
) -> impl Future<Output = Self::State>
fn hydrate_async( self, cursor: &Cursor, position: &PositionState, ) -> impl Future<Output = Self::State>
Asynchronously makes a set of DOM nodes rendered from HTML interactive.
Async hydration is useful for types that may need to wait before being hydrated: for example, lazily-loaded routes need async hydration, because the client code may be loading asynchronously, while the server HTML was already rendered.
Sourcefn hydrate_from<const FROM_SERVER: bool>(self, el: &Element) -> Self::Statewhere
Self: Sized,
fn hydrate_from<const FROM_SERVER: bool>(self, el: &Element) -> Self::Statewhere
Self: Sized,
Hydrates using RenderHtml::hydrate, beginning at the given element.
Sourcefn hydrate_from_position<const FROM_SERVER: bool>(
self,
el: &Element,
position: Position,
) -> Self::Statewhere
Self: Sized,
fn hydrate_from_position<const FROM_SERVER: bool>(
self,
el: &Element,
position: Position,
) -> Self::Statewhere
Self: Sized,
Hydrates using RenderHtml::hydrate, beginning at the given element and position.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.