liquid_core/runtime/
renderable.rs

1use std::fmt::Debug;
2use std::io::Write;
3
4use crate::error::Result;
5
6use super::Runtime;
7
8/// Any object (tag/block) that can be rendered by liquid must implement this trait.
9pub trait Renderable: Send + Sync + Debug {
10    /// Renders the Renderable instance given a Liquid runtime.
11    fn render(&self, runtime: &dyn Runtime) -> Result<String> {
12        let mut data = Vec::new();
13        self.render_to(&mut data, runtime)?;
14        Ok(String::from_utf8(data).expect("render only writes UTF-8"))
15    }
16
17    /// Renders the Renderable instance given a Liquid runtime.
18    fn render_to(&self, writer: &mut dyn Write, runtime: &dyn Runtime) -> Result<()>;
19}