1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::collections::HashMap;
use crate::{Component, InertiaError, InertiaProps};
use async_trait::async_trait;
use serde_json::Value;
#[async_trait(?Send)]
pub trait InertiaFacade<THttpRequest, TResponse, TRedirect> {
/// Renders an Inertia Page as an HTTP response.
///
/// # Arguments
/// * `req` - A reference to the HTTP request.
/// * `component` - The page javascript component name to be rendered by the
/// client-side adapter.
///
/// # Panic
/// Panics if Inertia instance hasn't been configured (set to AppData).
async fn render(req: &THttpRequest, component: Component) -> Result<TResponse, InertiaError>;
/// Renders an Inertia Page with props as an HTTP response.
///
/// # Arguments
/// * `req` - A reference to the HTTP request.
/// * `component` - The page component to be rendered by the client-side adapter.
/// * `props` - A `TProps` (serializable) struct containing
/// the props to be sent to the client-side.
///
/// # Errors
/// This operation may result in one of InertiaErrors if the props struct
/// or any of its fields don't implement [`Serialize`] trait.
///
/// # Panics
/// Panics if Inertia instance hasn't been configured (set to AppData).
///
/// [`Serialize`]: serde::Serialize
async fn render_with_props(
req: &THttpRequest,
component: Component,
props: InertiaProps<'_>,
) -> Result<TResponse, InertiaError>;
/// Provokes a client-side redirect to an extern URL.
///
/// # Arguments
/// * `req` - A reference to the HTTP request.
/// * `url` - The URL to be redirected to.
fn location(req: &THttpRequest, url: &str) -> TResponse;
/// Whether to encrypt or not the current request. Refer to [History Encrypt] for more
/// details.
///
/// [History Encrypt]: https://kaiofelps.github.io/inertia-rust/history-encrypt
fn encrypt_history(req: &THttpRequest, encrypt: bool);
/// Triggers a history clearing from server-side. Refer to [History Encrypt] for more
/// details.
///
/// [History Encrypt]: https://kaiofelps.github.io/inertia-rust/history-encrypt#clearing-history
fn clear_history(req: &THttpRequest);
/// Triggers a redirect to the previous URL (or "/", if there is no previous URL).
/// Please refer to [Flash Messages and Validation Errors] for more information.
///
/// [Flash Messages and Validation Errors]: https://kaiofelps.github.io/inertia-rust/advanced/flash-messages.html
fn back(req: &THttpRequest) -> TRedirect;
/// Triggers a redirect to the previous URL (or "/", if there is no previous URL) with
/// errors. Please refer to [Flash Messages and Validation Errors] for more information.
///
/// [Flash Messages and Validation Errors]: https://kaiofelps.github.io/inertia-rust/advanced/flash-messages.html
fn back_with_errors<Key: ToString>(
req: &THttpRequest,
errors: HashMap<Key, Value>,
) -> TRedirect;
/// Inserts custom view data to be accessed by the template root.
fn view_data(req: &THttpRequest, data: HashMap<&str, Value>);
/// Checks whether the request was made by the Inertia client router rather than a standard full-page load.
fn check_is_inertia_request(req: &THttpRequest) -> bool;
}