Skip to content

Commit

Permalink
feat: make TemplateRepository cloneable
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 29, 2017
1 parent 472fb63 commit 94f337a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,30 @@ pub trait Renderable: Send + Sync {
fn render(&self, context: &mut Context) -> Result<Option<String>>;
}

pub trait TemplateRepository {
pub trait TemplateRepository: Send + Sync + TemplateRepositoryClone {
fn read_template(&self, path: &str) -> Result<String>;
}

pub trait TemplateRepositoryClone {
fn clone_box(&self) -> Box<TemplateRepository>;
}

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

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

/// `TemplateRepository` to load files relative to the root
#[derive(Clone)]
pub struct LocalTemplateRepository {
root: PathBuf,
}
Expand Down

0 comments on commit 94f337a

Please sign in to comment.