Trait nickel_mustache::TemplateCache
[−]
[src]
pub trait TemplateCache {
fn handle<'a, P, F, R>(&self, path: &'a Path, handle: P, on_miss: F) -> R where P: FnOnce(Result<&Template, CompileError>) -> R, F: FnOnce(&'a Path) -> Result<Template, CompileError>;
}
Handle template caching through a borrowed reference.
Required Methods
fn handle<'a, P, F, R>(&self, path: &'a Path, handle: P, on_miss: F) -> R where P: FnOnce(Result<&Template, CompileError>) -> R, F: FnOnce(&'a Path) -> Result<Template, CompileError>
Handles a cache lookup for a given template.
Expected behavior
if let Some(template) = cache.get(path) {
return handle(template)
} else {
let template = on_miss(path);
return handle(template)
}
Fix-me!
The signature is a bit crazy, but due to the nature of the interior mutability
required it's difficult to express a general interface without restrictions
on the kinds of type TemplateCache
could be implemented for.
Any improvements to get it to a more entry
-like design are welcome!
Implementors
impl TemplateCache for ()
impl TemplateCache for RwLock<HashMap<PathBuf, Template>>