[−][src]Struct ramhorns::Template
A preprocessed form of the plain text template, ready to be rendered
with data contained in types implementing the Content
trait.
Methods
impl<'tpl> Template<'tpl>
[src]
pub fn new<Source>(source: Source) -> Result<Self, Error> where
Source: Into<Cow<'tpl, str>>,
[src]
Source: Into<Cow<'tpl, str>>,
Create a new Template
out of the source.
- If
Source
is a&str
, thisTemplate
will borrow it with appropriate lifetime. - If
Source
is aString
, thisTemplate
will take it's ownership (The'tpl
lifetime will be'static
).
pub fn capacity_hint(&self) -> usize
[src]
Estimate how big of a buffer should be allocated to render this Template
.
pub fn render<C: Content>(&self, content: &C) -> String
[src]
Render this Template
with a given Content
to a String
.
pub fn render_to_writer<W, C>(&self, writer: &mut W, content: &C) -> Result<()> where
W: Write,
C: Content,
[src]
W: Write,
C: Content,
Render this Template
with a given Content
to a writer.
pub fn render_to_file<P, C>(&self, path: P, content: &C) -> Result<()> where
P: AsRef<Path>,
C: Content,
[src]
P: AsRef<Path>,
C: Content,
Render this Template
with a given Content
to a file.
pub fn source(&self) -> &str
[src]
Get a reference to a source this Template
was created from.
impl Template<'static>
[src]
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>
[src]
Create a template from a file.
let tpl = Template::from_file("./templates/my_template.html").unwrap();
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,