Skip to main content

ViewHandle

Struct ViewHandle 

Source
pub struct ViewHandle { /* private fields */ }
Expand description

A handle to an HTML fragment.

A view handle 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>Hello

The outermost View returns a self-contained handle. It can be stored, sent to another task, or inserted into another view. Nested views return handles tied to the enclosing build. Those handles can only be rendered or inserted while that build is active.

Implementations§

Source§

impl ViewHandle

Source

pub fn size_hint(&self) -> usize

Returns an estimate of the number of bytes the view writes when rendered.

Source

pub fn empty() -> Self

Returns a ViewHandle that renders to an empty string.

Source

pub fn is_empty(&self) -> bool

Returns true if the view is statically known to render no output.

A view holding an instruction block reports false even when the block happens to write nothing.

Source

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.

Source

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.

§Panics

Panics if the view is a nested handle rendered outside the build it belongs to, or if a dynamic attribute key or element name in the view contains a character that could break out of the identifier.

Source

pub fn render_response(self, cx: &Cx) -> RenderedResponse

Available on crate feature 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.

§Panics

Panics if the view is a nested handle rendered outside the build it belongs to, or if a dynamic attribute key or element name in the view contains a character that could break out of the identifier.

Source

pub fn render_into(self, cx: &Cx, f: &mut Formatter<'_>)

Writes the view’s output through f.

The formatter appends to its destination as it goes, so reserve the size_hint up front to avoid reallocations. A nested handle renders against the buffer of the build it belongs to, which must be the one running on the current task.

§Panics

Panics if the view is a nested handle and no build is running on the current task, or a different one is, or if a dynamic attribute key or element name in the view contains a character that could break out of the identifier.

Trait Implementations§

Source§

impl Clone for ViewHandle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ViewHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ViewHandle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl NodeViewParts for ViewHandle

Source§

fn into_view_parts(self, _cx: &Cx, parts: &mut PartsWriter<'_>)

Appends this value to the view being built.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.