Skip to content

Commit

Permalink
feat: make ParseBlock cloneable
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 29, 2017
1 parent 1ce9709 commit 472fb63
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl ParseTag for FnTagParser {
/// of the block, the argument [Tokens](lexer/enum.Token.html) passed to
/// the block, a Vec of all [Elements](lexer/enum.Element.html) inside the block and
/// the global [`LiquidOptions`](struct.LiquidOptions.html).
pub trait ParseBlock: Send + Sync {
pub trait ParseBlock: Send + Sync + ParseBlockClone {
fn parse(&self,
tag_name: &str,
arguments: &[Token],
Expand All @@ -175,6 +175,24 @@ pub trait ParseBlock: Send + Sync {
-> Result<Box<Renderable>>;
}

pub trait ParseBlockClone {
fn clone_box(&self) -> Box<ParseBlock>;
}

impl<T> ParseBlockClone for T
where T: 'static + ParseBlock + Clone
{
fn clone_box(&self) -> Box<ParseBlock> {
Box::new(self.clone())
}
}

impl Clone for Box<ParseBlock> {
fn clone(&self) -> Box<ParseBlock> {
self.clone_box()
}
}

pub type FnParseBlock = fn(&str, &[Token], &[Element], &LiquidOptions) -> Result<Box<Renderable>>;

#[derive(Clone)]
Expand Down

0 comments on commit 472fb63

Please sign in to comment.