neutralts

Struct Template

Source
pub struct Template<'a> {
    raw: String,
    file_path: &'a str,
    schema: Value,
    shared: Shared,
    time_start: Instant,
    time_elapsed: Duration,
    out: String,
}

Fields§

§raw: String§file_path: &'a str§schema: Value§shared: Shared§time_start: Instant§time_elapsed: Duration§out: String

Implementations§

Source§

impl<'a> Template<'a>

A struct representing a template that can be rendered.

This struct is used to handle the rendering of templates.

Source

pub fn new() -> Result<Self, String>

Constructs a new Template instance with default settings.

It allows you to set up a template and schema with different types.

Source

pub fn from_file_value( file_path: &'a str, schema: Value, ) -> Result<Self, String>

Constructs a new Template instance from a file path and a JSON schema.

§Arguments
  • file_path - A reference to the path of the file containing the template content.
  • schema - A JSON value representing the custom schema to be used with the template.
§Returns

A Result containing the new Template instance or an error message if:

  • The file cannot be read.
Source

pub fn set_src_path(&mut self, file_path: &'a str) -> Result<(), String>

Sets the source path of the template.

§Arguments
  • file_path - A reference to the path of the file containing the template content.
§Returns

A Result indicating success or an error message if the file cannot be read

Source

pub fn set_src_str(&mut self, source: &str)

Sets the content of the template from a string.

§Arguments
  • source - A reference to the new string content to be set as the raw content.
Source

pub fn merge_schema_path(&mut self, schema_path: &str) -> Result<(), String>

Merges the schema from a file with the current template schema.

§Arguments
  • schema_path - A reference to the path of the file containing the schema content.
§Returns

A Result indicating success or an error message if:

  • The file cannot be read.
  • The file’s content is not a valid JSON string.
Source

pub fn merge_schema_str(&mut self, schema: &str) -> Result<(), String>

Merges the schema from a JSON string with the current template schema.

§Arguments
  • schema - A reference to the JSON string of the schema content.
§Returns

A Result indicating success or an error message if:

  • The file’s content is not a valid JSON string.
Source

pub fn merge_schema_value(&mut self, schema: Value)

Merges the provided JSON value with the current schema.

§Arguments
  • schema - The JSON Value to be merged with the current schema.
Source

pub fn render(&mut self) -> String

Renders the template content.

This function initializes the rendering process. The resulting output is returned as a string.

§Returns

The rendered template content as a string.

Source

fn init_render(&mut self) -> BlockInherit

Source

fn ends_render(&mut self)

Source

fn set_status_code(&mut self)

Source

fn set_moveto(&mut self)

Source

fn replacements(&mut self)

Source

pub fn get_status_code(&self) -> &String

Retrieves the status code.

The status code is “200” unless “exit”, “redirect” is used or the template contains a syntax error, which will return a status code of “500”. Although the codes are numeric, a string is returned.

§Returns

A reference to the status code as a string.

Source

pub fn get_status_text(&self) -> &String

Retrieves the status text.

It will correspond to the one set by the HTTP protocol.

§Returns

A reference to the status text as a string.

Source

pub fn get_status_param(&self) -> &String

Retrieves the status parameter.

Some statuses such as 301 (redirect) may contain additional data, such as the destination URL, and in similar cases “param” will contain that value.

§Returns

A reference to the status parameter as a string.

Source

pub fn has_error(&self) -> bool

Checks if there is an error.

If any error has occurred, in the parse or otherwise, it will return true.

§Returns

A boolean indicating whether there is an error.

Source

pub fn get_error(&self) -> Value

Get bifs errors list

§Returns
  • Value: A clone of the value with the list of errors in the bifs during rendering.
Source

pub fn get_time_duration(&self) -> Duration

Retrieves the time duration for template rendering.

§Returns

The time duration elapsed .

Auto Trait Implementations§

§

impl<'a> Freeze for Template<'a>

§

impl<'a> RefUnwindSafe for Template<'a>

§

impl<'a> Send for Template<'a>

§

impl<'a> Sync for Template<'a>

§

impl<'a> Unpin for Template<'a>

§

impl<'a> UnwindSafe for Template<'a>

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Ungil for T
where T: Send,