[]Struct sigma::Sigma

pub struct Sigma<'s> { /* fields omitted */ }

Sigma, Template Language made simple !

Example:

let result = Sigma::new("Hello {{ username }}") // using {{ ... }} for the template.
    .bind("username", "someone") // bind the vars with values
    .parse() // you must parse your template first
    .map_err(|e| eprintln!("{}", e))? // for pretty printing the error..
    .compile()
    .map_err(|e| eprintln!("{}", e))?;
assert_eq!("Hello someone", result);

Methods

impl<'s> Sigma<'s>

pub fn new(input: &'s str) -> Self

Create new Sigma with some template

pub fn bind(self, key: &'s str, value: &'s str) -> Self

bind some key in the template for some value

pub fn bind_map(self, map: HashMap<&'s str, &'s str>) -> Self

bind one or more keys with values in one run.

pub fn override_bind(self, map: HashMap<&'s str, &'s str>) -> Self

remove all the previous binded keys, and use that one

pub fn ignore_unbinded(self) -> Self

ignore parse error for unbinded variables

pub fn register_fn(
    self,
    func_name: &'static str,
    func: fn(_: String) -> String
) -> Self

register a helper function

The Function Name Must be in UPPERCASE

pub fn parse(self) -> Result<Self, PestError<Rule>>

Parse the template before compiling it to ensure no runtime erros.

pub fn compile(self) -> Result<String, PestError<Rule>>

Compile the template with the binded values

Panics

this will panic if the current template not parsed yet.

Trait Implementations

impl<'s> PartialEq<Sigma<'s>> for Sigma<'s>

impl<'s> Eq for Sigma<'s>

impl<'s> Clone for Sigma<'s>

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'s> From<&'s str> for Sigma<'s>

impl<'s> Debug for Sigma<'s>

Auto Trait Implementations

impl<'s> Send for Sigma<'s>

impl<'s> Sync for Sigma<'s>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]