Skip to content

Commit

Permalink
template reload: require the customization callback be Fn + Copy (c…
Browse files Browse the repository at this point in the history
…opy_closures stabilized)

this change makes the `Mutex<Option>` wrapper unnecessary
  • Loading branch information
jebrosen committed Apr 3, 2018
1 parent 4bd9dcf commit 8850f35
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions contrib/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use self::glob::glob;

use std::borrow::Cow;
use std::path::PathBuf;
use std::sync::Mutex;
#[cfg(debug_assertions)]
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};

Expand Down Expand Up @@ -238,8 +237,7 @@ impl Template {
/// # ;
/// }
/// ```
pub fn custom<F>(f: F) -> impl Fairing where F: Fn(&mut Engines) + Send + Sync + 'static {
let callback = Mutex::new(Some(Box::new(f)));
pub fn custom<F>(f: F) -> impl Fairing where F: Fn(&mut Engines) + Copy + Send + Sync + 'static {
AdHoc::on_attach(move |rocket| {
let mut template_root = rocket.config().root_relative(DEFAULT_TEMPLATE_DIR);
match rocket.config().get_str("template_dir") {
Expand All @@ -251,9 +249,7 @@ impl Template {
}
};

let callback = callback.lock().unwrap().take().expect("on_attach fairing called twice!");

let ctxt = match Context::initialize(template_root, callback) {
let ctxt = match Context::initialize(template_root, Box::new(f)) {
Some(ctxt) => ctxt,
None => return Err(rocket),
};
Expand Down

0 comments on commit 8850f35

Please sign in to comment.