Struct liquid::Parser

source ·
pub struct Parser { /* private fields */ }

Implementations§

source§

impl Parser

source

pub fn new() -> Self

source

pub fn parse(&self, text: &str) -> Result<Template>

Parses a liquid template, returning a Template object.

Examples
Minimal Template
let template = liquid::ParserBuilder::with_stdlib()
    .build().unwrap()
    .parse("Liquid!").unwrap();

let globals = liquid::Object::new();
let output = template.render(&globals).unwrap();
assert_eq!(output, "Liquid!".to_string());
source

pub fn parse_file<P: AsRef<Path>>(&self, file: P) -> Result<Template>

Parse a liquid template from a file, returning a Result<Template, Error>.

Examples
Minimal Template

template.txt:

"Liquid {{data}}"

Your rust code:

let template = liquid::ParserBuilder::with_stdlib()
    .build().unwrap()
    .parse_file("path/to/template.txt").unwrap();

let globals = liquid::object!({
    "data": 4f64,
});
let output = template.render(&globals).unwrap();
assert_eq!(output, "Liquid! 4\n".to_string());

Trait Implementations§

source§

impl Clone for Parser

source§

fn clone(&self) -> Parser

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Parser

source§

fn default() -> Parser

Returns the “default value” for a type. Read more
source§

impl ParserReflection for Parser

source§

fn blocks<'r>(&'r self) -> Box<dyn Iterator<Item = &dyn BlockReflection> + 'r>

source§

fn tags<'r>(&'r self) -> Box<dyn Iterator<Item = &dyn TagReflection> + 'r>

source§

fn filters<'r>(&'r self) -> Box<dyn Iterator<Item = &dyn FilterReflection> + 'r>

source§

fn partials<'r>(&'r self) -> Box<dyn Iterator<Item = &str> + 'r>

Auto Trait Implementations§

§

impl !RefUnwindSafe for Parser

§

impl Send for Parser

§

impl Sync for Parser

§

impl Unpin for Parser

§

impl !UnwindSafe for Parser

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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<T> Any for Twhere T: Any,

§

impl<T> CloneAny for Twhere T: Any + Clone,

§

impl<T> CloneAnySend for Twhere T: Any + Send + Clone,

§

impl<T> CloneAnySendSync for Twhere T: Any + Send + Sync + Clone,

§

impl<T> CloneAnySync for Twhere T: Any + Sync + Clone,