oxiplate/
lib.rs

1#![doc(issue_tracker_base_url = "https://github.com/0b10011/oxiplate/issues/")]
2#![doc(test(no_crate_inject))]
3#![doc(test(attr(deny(warnings))))]
4#![doc = include_str!("../README.md")]
5#![warn(missing_docs)]
6
7use core::fmt::{Error, Write};
8
9pub use oxiplate_derive::Oxiplate;
10
11pub mod escapers;
12pub mod unescaped_text;
13
14/// Optimized render function trait.
15pub trait Render {
16    /// Estimated output length of the template.
17    const ESTIMATED_LENGTH: usize;
18
19    /// Render the template into a string.
20    ///
21    /// # Errors
22    ///
23    /// If strings cannot be written to the formatter.
24    fn render(&self) -> Result<String, Error> {
25        let mut string = String::with_capacity(Self::ESTIMATED_LENGTH);
26        self.render_into(&mut string)?;
27        Ok(string)
28    }
29
30    /// Render the template into a writer.
31    ///
32    /// # Errors
33    ///
34    /// If strings cannot be written to the formatter.
35    fn render_into<W: Write>(&self, writer: &mut W) -> ::std::fmt::Result;
36}