diff --git a/.travis.yml b/.travis.yml index 02b7561..004d35f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ cache: - target rust: -- 1.46.0 - stable - nightly - beta diff --git a/Cargo.toml b/Cargo.toml index 4586cea..d15c8b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "mustache" 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" +version = "0.9.1" authors = ["erick.tryzelaar@gmail.com"] license = "MIT/Apache-2.0" @@ -11,13 +11,13 @@ license = "MIT/Apache-2.0" unstable = [] [dependencies] -log = "0.3.5" +log = "0.4" serde = "1.0.0" [dev-dependencies] serde_derive = "1.0.0" serde_json = "1.0.0" -tempdir = "0.3.4" +tempfile = "3" [[test]] name = "test" diff --git a/src/builder.rs b/src/builder.rs index 83c5ca4..d1b48dc 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -37,7 +37,7 @@ impl MapBuilder { let MapBuilder { mut data } = self; let value = to_data(value)?; data.insert(key.into(), value); - Ok(MapBuilder { data: data }) + Ok(MapBuilder { data }) } /// Add a `String` to the `MapBuilder`. @@ -56,7 +56,7 @@ impl MapBuilder { { let MapBuilder { mut data } = self; data.insert(key.into(), Data::String(value.into())); - MapBuilder { data: data } + MapBuilder { data } } /// Add a `bool` to the `MapBuilder`. @@ -74,7 +74,7 @@ impl MapBuilder { { let MapBuilder { mut data } = self; data.insert(key.into(), Data::Bool(value)); - MapBuilder { data: data } + MapBuilder { data } } /// Add a `Vec` to the `MapBuilder`. @@ -97,7 +97,7 @@ impl MapBuilder { let MapBuilder { mut data } = self; let builder = f(VecBuilder::new()); data.insert(key.into(), builder.build()); - MapBuilder { data: data } + MapBuilder { data } } /// Add a `Map` to the `MapBuilder`. @@ -126,7 +126,7 @@ impl MapBuilder { let MapBuilder { mut data } = self; let builder = f(MapBuilder::new()); data.insert(key.into(), builder.build()); - MapBuilder { data: data } + MapBuilder { data } } /// Add a function to the `MapBuilder`. @@ -147,7 +147,7 @@ impl MapBuilder { { let MapBuilder { mut data } = self; data.insert(key.to_string(), Data::Fun(RefCell::new(Box::new(f)))); - MapBuilder { data: data } + MapBuilder { data } } /// Return the built `Data`. @@ -183,7 +183,7 @@ impl VecBuilder { let VecBuilder { mut data } = self; let value = to_data(value)?; data.push(value); - Ok(VecBuilder { data: data }) + Ok(VecBuilder { data }) } /// Add a `String` to the `VecBuilder`. @@ -199,7 +199,7 @@ impl VecBuilder { pub fn push_str(self, value: T) -> VecBuilder { let VecBuilder { mut data } = self; data.push(Data::String(value.to_string())); - VecBuilder { data: data } + VecBuilder { data } } /// Add a `bool` to the `VecBuilder`. @@ -215,7 +215,7 @@ impl VecBuilder { pub fn push_bool(self, value: bool) -> VecBuilder { let VecBuilder { mut data } = self; data.push(Data::Bool(value)); - VecBuilder { data: data } + VecBuilder { data } } /// Add a `Vec` to the `MapBuilder`. @@ -237,7 +237,7 @@ impl VecBuilder { let VecBuilder { mut data } = self; let builder = f(VecBuilder::new()); data.push(builder.build()); - VecBuilder { data: data } + VecBuilder { data } } /// Add a `Map` to the `VecBuilder`. @@ -264,7 +264,7 @@ impl VecBuilder { let VecBuilder { mut data } = self; let builder = f(MapBuilder::new()); data.push(builder.build()); - VecBuilder { data: data } + VecBuilder { data } } /// Add a function to the `VecBuilder`. @@ -285,7 +285,7 @@ impl VecBuilder { { let VecBuilder { mut data } = self; data.push(Data::Fun(RefCell::new(Box::new(f)))); - VecBuilder { data: data } + VecBuilder { data } } #[inline] diff --git a/src/compiler.rs b/src/compiler.rs index b40e558..de3805b 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -23,8 +23,8 @@ impl> Compiler { /// Construct a default compiler. pub fn new(ctx: Context, reader: T) -> Compiler { Compiler { - ctx: ctx, - reader: reader, + ctx, + reader, partials: HashMap::new(), otag: "{{".to_string(), ctag: "}}".to_string(), @@ -38,13 +38,7 @@ impl> Compiler { otag: String, ctag: String) -> Compiler { - Compiler { - ctx: ctx, - reader: reader, - partials: partials, - otag: otag, - ctag: ctag, - } + Compiler { ctx, reader, partials, otag, ctag } } /// Compiles a template into a series of tokens. @@ -59,6 +53,9 @@ impl> Compiler { let path = self.ctx.template_path.join(&(name.clone() + "." + &self.ctx.template_extension)); + // This is too complicated to just be + // self.partials.entry(&name).or_insert(...) + #[allow(clippy::map_entry)] if !self.partials.contains_key(&name) { // Insert a placeholder so we don't recurse off to infinity. self.partials.insert(name.to_string(), Vec::new()); diff --git a/src/data.rs b/src/data.rs index dbb7b20..e13567d 100644 --- a/src/data.rs +++ b/src/data.rs @@ -3,7 +3,7 @@ use std::cell::RefCell; use std::fmt; // for bug! -use log::{log, error}; +use log::error; pub enum Data { Null, diff --git a/src/encoder.rs b/src/encoder.rs index c333b34..0c7cf1b 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -12,6 +12,7 @@ use super::{Data, to_data}; /// This type is not intended to be matched exhaustively as new variants /// may be added in future without a version bump. #[derive(Debug)] +#[non_exhaustive] pub enum Error { NestedOptions, UnsupportedType, @@ -19,9 +20,6 @@ pub enum Error { KeyIsNotString, NoDataToEncode, Message(String), - - #[doc(hidden)] - __Nonexhaustive, } impl serde::ser::Error for Error { @@ -42,7 +40,6 @@ impl fmt::Display for Error { Error::KeyIsNotString => "key is not a string", Error::NoDataToEncode => "the encodable type created no data", Error::Message(ref s) => s, - Error::__Nonexhaustive => unreachable!(), }) } } diff --git a/src/error.rs b/src/error.rs index 054c545..5604fde 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,6 +10,7 @@ use encoder; /// This type is not intended to be matched exhaustively as new variants /// may be added in future without a version bump. #[derive(Debug)] +#[non_exhaustive] pub enum Error { InvalidStr, NoFilename, @@ -17,9 +18,6 @@ pub enum Error { Io(StdIoError), Parser(parser::Error), Encoder(encoder::Error), - - #[doc(hidden)] - __Nonexhaustive, } pub type Result = StdResult; @@ -33,7 +31,6 @@ impl fmt::Display for Error { Error::Io(ref err) => err.to_string(), Error::Parser(ref err) => err.to_string(), Error::Encoder(ref err) => err.to_string(), - Error::__Nonexhaustive => unreachable!(), }) } } diff --git a/src/lib.rs b/src/lib.rs index 5a5e705..d36219c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,13 +43,13 @@ pub fn compile_iter>(iter: T) -> Result