inertia_rust/template_resolver.rs
1use async_trait::async_trait;
2
3use crate::{InertiaError, ViewData};
4
5#[async_trait(?Send)]
6pub trait TemplateResolver {
7 /// A function responsible for rendering the root template
8 /// with the given **view data**.
9 ///
10 /// This should be relative by the template engine you are using, and it is mandatory for
11 /// rendering the HTML to be served on full requests. Since Rust does not offer a standard
12 /// template engine, there are various options, and it is not our goal to tie you to a specific
13 /// one which we opted to use.
14 ///
15 /// # Arguments
16 /// Inertia will call this function passing the following parameters to it:
17 /// * `view_data` - A [`ViewData`] struct,
18 ///
19 /// # Errors
20 /// Returns an [`InertiaError::RenderError`] if it fails to render the html.
21 ///
22 /// # Return
23 /// The return must be the template rendered to HTML. It will be sent as response to full
24 /// requests.
25 async fn resolve_template(&self, view_data: ViewData<'_>) -> Result<String, InertiaError>;
26}