Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.44k stars 280 forks source link

Can I use file output stream instead of write? #934

Closed duhbbx closed 3 weeks ago

duhbbx commented 3 weeks ago

I want to use tera to render a very large word, perhaps with thousands of pages, but the current implementation seems to put it in memory first.

I want to use file stream instead of write here, and then output the rendered results to the file. Is this feasible?

    /// Entry point for the rendering
    pub fn render(&mut self, write: &mut impl Write) -> Result<()> {
        for node in &self.template_root.ast {
            self.render_node(node, write)
                .map_err(|e| Error::chain(self.get_error_location(), e))?;
        }

        Ok(())
    }
Keats commented 3 weeks ago

Does https://docs.rs/tera/latest/tera/struct.Tera.html#method.render_to work for you?

duhbbx commented 3 weeks ago

Thank you very much, I'll try it later