1use liquid_error::Result;
2use liquid_interpreter::Renderable;
3
4use super::Language;
5use super::TagBlock;
6use super::TagTokenIter;
7
8pub trait BlockReflection {
9 fn start_tag(&self) -> &'static str;
10
11 fn end_tag(&self) -> &'static str;
12
13 fn description(&self) -> &'static str;
14
15 fn example(&self) -> Option<&'static str> {
16 None
17 }
18
19 fn spec(&self) -> Option<&'static str> {
20 None
21 }
22}
23
24pub trait ParseBlock: Send + Sync + ParseBlockClone + BlockReflection {
33 fn parse(
34 &self,
35 arguments: TagTokenIter,
36 block: TagBlock,
37 options: &Language,
38 ) -> Result<Box<Renderable>>;
39}
40
41pub trait ParseBlockClone {
42 fn clone_box(&self) -> Box<ParseBlock>;
43}
44
45impl<T> ParseBlockClone for T
46where
47 T: 'static + ParseBlock + Clone,
48{
49 fn clone_box(&self) -> Box<ParseBlock> {
50 Box::new(self.clone())
51 }
52}
53
54impl Clone for Box<ParseBlock> {
55 fn clone(&self) -> Box<ParseBlock> {
56 self.clone_box()
57 }
58}
59
60impl<T> From<T> for Box<ParseBlock>
61where
62 T: 'static + ParseBlock,
63{
64 fn from(filter: T) -> Self {
65 Box::new(filter)
66 }
67}