Skip to content

Commit

Permalink
Eliminate most of the clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Stern committed Apr 4, 2021
1 parent 5ec95d0 commit 94afdba
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 52 deletions.
24 changes: 12 additions & 12 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand Down Expand Up @@ -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`.
Expand All @@ -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`.
Expand Down Expand Up @@ -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`.
Expand All @@ -199,7 +199,7 @@ impl VecBuilder {
pub fn push_str<T: ToString>(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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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]
Expand Down
12 changes: 3 additions & 9 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl<T: Iterator<Item = char>> Compiler<T> {
/// Construct a default compiler.
pub fn new(ctx: Context, reader: T) -> Compiler<T> {
Compiler {
ctx: ctx,
reader: reader,
ctx,
reader,
partials: HashMap::new(),
otag: "{{".to_string(),
ctag: "}}".to_string(),
Expand All @@ -38,13 +38,7 @@ impl<T: Iterator<Item = char>> Compiler<T> {
otag: String,
ctag: String)
-> Compiler<T> {
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.
Expand Down
5 changes: 1 addition & 4 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ 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,
MissingElements,
KeyIsNotString,
NoDataToEncode,
Message(String),

#[doc(hidden)]
__Nonexhaustive,
}

impl serde::ser::Error for Error {
Expand All @@ -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!(),
})
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ 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,
IncompleteSection,
Io(StdIoError),
Parser(parser::Error),
Encoder(encoder::Error),

#[doc(hidden)]
__Nonexhaustive,
}

pub type Result<T> = StdResult<T, Error>;
Expand All @@ -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!(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn compile_path<U: AsRef<Path>>(path: U) -> Result<Template> {

match path.file_name() {
Some(filename) => {
let template_dir = path.parent().unwrap_or(Path::new("."));
let template_dir = path.parent().unwrap_or_else(|| Path::new("."));
// FIXME: Should work with OsStrings, this will not use provided extension if
// the extension is not utf8 :(
let extension = path.extension().and_then(|ext| ext.to_str()).unwrap_or("mustache");
Expand Down
13 changes: 5 additions & 8 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum Token {
/// This type is not intended to be matched exhaustively as new variants
/// may be added in future without a version bump.
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
BadClosingTag(char, char),
UnclosedTag,
Expand All @@ -30,9 +31,6 @@ pub enum Error {
EarlySectionClose(String),
MissingSetDelimeterClosingTag,
InvalidSetDelimeterSyntax,

#[doc(hidden)]
__Nonexhaustive,
}

impl StdError for Error { }
Expand All @@ -49,7 +47,6 @@ impl fmt::Display for Error {
Error::EmptyTag => write!(f, "found an empty tag",),
Error::MissingSetDelimeterClosingTag => write!(f, "missing the new closing tag in set delimeter tag"),
Error::InvalidSetDelimeterSyntax => write!(f, "invalid set delimeter tag syntax"),
Error::__Nonexhaustive => unreachable!(),
}
}
}
Expand Down Expand Up @@ -88,7 +85,7 @@ enum ParserState {
impl<'a, T: Iterator<Item = char>> Parser<'a, T> {
pub fn new(reader: &'a mut T, opening_tag: &str, closing_tag: &str) -> Parser<'a, T> {
let mut parser = Parser {
reader: reader,
reader,
ch: None,
lookahead: None,
line: 1,
Expand Down Expand Up @@ -172,7 +169,7 @@ impl<'a, T: Iterator<Item = char>> Parser<'a, T> {
curly_brace_tag = false;
self.state = ParserState::Tag;
} else {
self.tag_position = self.tag_position + 1;
self.tag_position += 1;
}
} else {
// We don't have a tag, so add all the tag parts we've seen
Expand Down Expand Up @@ -523,7 +520,7 @@ impl<'a, T: Iterator<Item = char>> Parser<'a, T> {

fn not_otag(&mut self) {
for (i, ch) in self.opening_tag_chars.iter().enumerate() {
if !(i < self.tag_position) {
if i >= self.tag_position {
break;
}
self.content.push(*ch);
Expand All @@ -532,7 +529,7 @@ impl<'a, T: Iterator<Item = char>> Parser<'a, T> {

fn not_ctag(&mut self) {
for (i, ch) in self.closing_tag_chars.iter().enumerate() {
if !(i < self.tag_position) {
if i >= self.tag_position {
break;
}
self.content.push(*ch);
Expand Down
21 changes: 7 additions & 14 deletions src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ pub struct Template {
/// Construct a `Template`. This is not part of the impl of Template so it is
/// not exported outside of mustache.
pub fn new(ctx: Context, tokens: Vec<Token>, partials: HashMap<String, Vec<Token>>) -> Template {
Template {
ctx: ctx,
tokens: tokens,
partials: partials,
}
Template { ctx, tokens, partials }
}

impl Template {
Expand Down Expand Up @@ -71,8 +67,8 @@ struct RenderContext<'a> {
impl<'a> RenderContext<'a> {
fn new(template: &'a Template) -> RenderContext<'a> {
RenderContext {
template: template,
indent: "".to_string(),
template,
indent: String::new(),
line_start: true,
}
}
Expand Down Expand Up @@ -340,14 +336,11 @@ impl<'a> RenderContext<'a> {
let mut value = None;

for data in stack.iter().rev() {
match **data {
Data::Map(ref m) => {
if let Some(v) = m.get(&path[0]) {
value = Some(v);
break;
}
if let Data::Map(m) = *data {
if let Some(v) = m.get(&path[0]) {
value = Some(v);
break;
}
_ => { /* continue searching the stack */ },
}
}

Expand Down

0 comments on commit 94afdba

Please sign in to comment.