From c1c64419eb7aea4711f9cc3dc299d32f4588d568 Mon Sep 17 00:00:00 2001 From: Junfeng Liu Date: Fri, 7 Dec 2018 23:51:18 +0800 Subject: [PATCH] Fix clippy warnings --- src/parser.rs | 12 +++++++----- src/result.rs | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 1c5987c..6aece11 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -5,9 +5,11 @@ use crate::set::Set; use std::fmt::{Debug, Display}; use std::ops::{Add, BitOr, Mul, Neg, Not, Shr, Sub}; +type Parse<'a, I, O> = Fn(&'a [I], usize) -> Result<(O, usize)> + 'a; + /// Parser combinator. pub struct Parser<'a, I, O> { - method: Box Result<(O, usize)> + 'a>, + method: Box>, } impl<'a, I, O> Parser<'a, I, O> { @@ -77,7 +79,7 @@ impl<'a, I, O> Parser<'a, I, O> { results .borrow_mut() .entry(key) - .or_insert((self.method)(input, start)) + .or_insert_with(||(self.method)(input, start)) .clone() }) } @@ -174,7 +176,7 @@ impl<'a, I, O> Parser<'a, I, O> { }); } } - return Ok((items, pos)); + Ok((items, pos)) }) } @@ -288,7 +290,7 @@ pub fn tag<'a, 'b: 'a>(tag: &'b str) -> Parser<'a, char, &'a str> { } pos += 1; } - return Ok((tag, pos)); + Ok((tag, pos)) }) } @@ -318,7 +320,7 @@ where } } } - return Ok((items, pos)); + Ok((items, pos)) }) } diff --git a/src/result.rs b/src/result.rs index 1b474cd..78ff16b 100644 --- a/src/result.rs +++ b/src/result.rs @@ -20,17 +20,17 @@ impl error::Error for Error { impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - &Error::Incomplete => + Error::Incomplete => write!(f, "Incomplete"), - &Error::Mismatch { ref message, ref position } => + Error::Mismatch { ref message, ref position } => write!(f, "Mismatch at {}: {}", position, message), - &Error::Conversion { ref message, ref position } => + Error::Conversion { ref message, ref position } => write!(f, "Conversion failed at {}: {}", position, message), - &Error::Expect { ref message, ref position, ref inner } => + Error::Expect { ref message, ref position, ref inner } => write!(f, "{} at {}: {}", message, position, inner), - &Error::Custom { ref message, ref position, inner: Some(ref inner) } => + Error::Custom { ref message, ref position, inner: Some(ref inner) } => write!(f, "{} at {}, (inner: {})", message, position, inner), - &Error::Custom { ref message, ref position, inner: None } => + Error::Custom { ref message, ref position, inner: None } => write!(f, "{} at {}", message, position), } }