diff --git a/.travis.yml b/.travis.yml index 55904342..02b75619 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,7 @@ cache: - target rust: -- 1.16.0 -- 1.17.0 +- 1.46.0 - stable - nightly - beta diff --git a/Cargo.toml b/Cargo.toml index 4586cea5..48120590 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,8 @@ description = "Rust implementation of Mustache" repository = "https://github.com/nickel-org/rust-mustache" documentation = "http://nickel-org.github.io/rust-mustache" version = "0.9.0" +autotests = false +edition = "2021" authors = ["erick.tryzelaar@gmail.com"] license = "MIT/Apache-2.0" diff --git a/README.md b/README.md index 7c3cb778..89755a32 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ git push --tags origin master [1]: http://code.google.com/p/google-ctemplate/ [2]: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html [3]: https://mustache.github.io/ -[4]: http://mustache.github.com/mustache.5.html +[4]: https://mustache.github.io/mustache.5.html [5]: https://docs.rs/mustache # License diff --git a/src/builder.rs b/src/builder.rs index 83c5ca47..ecdddc29 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -3,11 +3,11 @@ use std::string::ToString; use std::collections::HashMap; use serde::Serialize; -use encoder::Error; +use crate::encoder::Error; use super::{Data, to_data}; /// `MapBuilder` is a helper type that construct `Data` types. -#[derive(Default)] +#[derive(Default, Debug)] pub struct MapBuilder { data: HashMap, } @@ -149,6 +149,15 @@ impl MapBuilder { data.insert(key.to_string(), Data::Fun(RefCell::new(Box::new(f)))); MapBuilder { data: data } } + #[inline] + pub fn insert_fn2(self, key: K, f: F) -> MapBuilder + where + F: FnMut(String, &mut dyn FnMut(String) -> String) -> String + Send + 'static, + { + let MapBuilder { mut data } = self; + data.insert(key.to_string(), Data::Fun2(RefCell::new(Box::new(f)))); + MapBuilder { data: data } + } /// Return the built `Data`. #[inline] diff --git a/src/compiler.rs b/src/compiler.rs index dcd6eae2..834cfd2a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -3,10 +3,10 @@ use std::io::ErrorKind::NotFound; use std::io::Read; use std::fs::File; -use parser::{Parser, Token}; +use crate::parser::{Parser, Token}; use super::Context; -use Result; +use crate::Result; pub type PartialsMap = HashMap>; @@ -51,7 +51,7 @@ impl> Compiler { pub fn compile(mut self) -> Result<(Vec, PartialsMap)> { let (tokens, partials) = { let parser = Parser::new(&mut self.reader, &self.otag, &self.ctag); - try!(parser.parse()) + parser.parse()? }; // Compile the partials if we haven't done so already. @@ -66,7 +66,7 @@ impl> Compiler { match File::open(&path) { Ok(mut file) => { let mut string = String::new(); - try!(file.read_to_string(&mut string)); + file.read_to_string(&mut string)?; let compiler = Compiler { ctx: self.ctx.clone(), @@ -76,7 +76,7 @@ impl> Compiler { ctag: "}}".to_string(), }; - let (tokens, subpartials) = try!(compiler.compile()); + let (tokens, subpartials) = compiler.compile()?; // Include subpartials self.partials.extend(subpartials.into_iter()); @@ -101,9 +101,9 @@ impl> Compiler { mod tests { use std::path::PathBuf; - use parser::Token; - use compiler::Compiler; - use context::Context; + use crate::parser::Token; + use crate::compiler::Compiler; + use crate::context::Context; fn compile_str(template: &str) -> Vec { let ctx = Context::new(PathBuf::from(".")); diff --git a/src/context.rs b/src/context.rs index e95aef69..906ad888 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,6 +1,6 @@ -use template::{self, Template}; -use compiler; -use {Result, Error}; +use crate::template::{self, Template}; +use crate::compiler; +use crate::{Result, Error}; use std::fmt; use std::fs::File; @@ -37,7 +37,7 @@ impl Context { /// Compiles a template from a string pub fn compile>(&self, reader: IT) -> Result