HtmlConstructor

Struct HtmlConstructor 

Source
pub struct HtmlConstructor;
Expand description

§Html Constructor

Loads a html file and constructs it for dynamic web loading

For example, when loading a template, you can pass through variables in a vec to implement them in your page

You can use this for things like user info or other server side information

Alternatively you could create a static page with JavaScript that loads this information from a webapi route on the same server.

Dynamic variables are defined as [ var_name ] in HTML, and just var_name in the Vars hashmap

Here is an example:

<p>[ test_var ]</p>
let mut vars = Vars::new();
vars.insert("test_var".to_string(), Variable::String("Test".to_string()));

This example shows a basic example of how the HTML code matches to Rust.

Please note that if there is no variable defined in the hashmap, it will not update with any dynamic values, and remain static. If the variable in the hashmap doesn’t find the variable in the HTML, nothing will happen there as well.

Implementations§

Source§

impl HtmlConstructor

Source

pub async fn construct_page( response_code: Response, path: &str, vars: Vars, ) -> String

§Construct Page

Takes in a file path (to the HTML file) and a Vars type.

Constructs the HTML page, returning a string value (also assigns all dynamic variables if any)

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.