pub struct View<T> { /* private fields */ }Expand description
A response that renders a template with a context
This is the primary way to render HTML templates in RustAPI handlers.
§Example
ⓘ
use rustapi_view::{View, Templates};
use serde::Serialize;
#[derive(Serialize)]
struct HomeContext {
title: String,
}
async fn home(templates: State<Templates>) -> View<HomeContext> {
View::render(&templates, "home.html", HomeContext {
title: "Home".to_string(),
})
}Implementations§
Source§impl<T: Serialize> View<T>
impl<T: Serialize> View<T>
Sourcepub async fn render(templates: &Templates, template: &str, context: T) -> Self
pub async fn render(templates: &Templates, template: &str, context: T) -> Self
Create a view by rendering a template with a serializable context
This is an async operation that renders the template immediately.
For deferred rendering, use View::deferred.
Sourcepub async fn render_with_status(
templates: &Templates,
template: &str,
context: T,
status: StatusCode,
) -> Self
pub async fn render_with_status( templates: &Templates, template: &str, context: T, status: StatusCode, ) -> Self
Create a view with a specific status code
Sourcepub fn status(self, status: StatusCode) -> Self
pub fn status(self, status: StatusCode) -> Self
Set the status code
Source§impl View<()>
impl View<()>
Sourcepub async fn render_context(
templates: &Templates,
template: &str,
context: &Context,
) -> Self
pub async fn render_context( templates: &Templates, template: &str, context: &Context, ) -> Self
Create a view by rendering a template with a tera Context
Trait Implementations§
Source§impl<T> IntoResponse for View<T>
impl<T> IntoResponse for View<T>
Source§impl<T> ResponseModifier for View<T>
impl<T> ResponseModifier for View<T>
Source§fn update_response(op: &mut Operation)
fn update_response(op: &mut Operation)
Update the operation with response information
Auto Trait Implementations§
impl<T> Freeze for View<T>
impl<T> !RefUnwindSafe for View<T>
impl<T> Send for View<T>where
T: Send,
impl<T> Sync for View<T>where
T: Sync,
impl<T> Unpin for View<T>where
T: Unpin,
impl<T> !UnwindSafe for View<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more