summaryrefslogtreecommitdiffstats
path: root/src/path
diff options
context:
space:
mode:
authorRyan Leckey <ryan@launchbadge.com>2017-06-13 02:21:46 -0700
committerRyan Leckey <ryan@launchbadge.com>2017-06-13 02:21:46 -0700
commitab0d8cb9aa107c8d561f3c188e6cbf472a7df23b (patch)
tree80545ea4305763bbf47a9bd33f4da99d6c9b985b /src/path
parentbabd49242c04e783ae27ea159e2bc42d24490520 (diff)
:shirt: Fix clippy warnings
Diffstat (limited to 'src/path')
-rw-r--r--src/path/mod.rs12
-rw-r--r--src/path/parser.rs11
2 files changed, 12 insertions, 11 deletions
diff --git a/src/path/mod.rs b/src/path/mod.rs
index d2df442..ff93287 100644
--- a/src/path/mod.rs
+++ b/src/path/mod.rs
@@ -17,12 +17,12 @@ impl FromStr for Expression {
type Err = ConfigError;
fn from_str(s: &str) -> Result<Expression> {
- parser::from_str(s).map_err(|kind| ConfigError::PathParse(kind))
+ parser::from_str(s).map_err(ConfigError::PathParse)
}
}
impl Expression {
- pub fn get<'a>(self, root: &'a Value) -> Option<&'a Value> {
+ pub fn get(self, root: &Value) -> Option<&Value> {
match self {
Expression::Identifier(id) => {
match root.kind {
@@ -61,7 +61,7 @@ impl Expression {
Expression::Identifier(ref id) => {
match root.kind {
ValueKind::Table(ref mut map) => {
- Some(map.entry(id.clone()).or_insert(Value::new(None, ValueKind::Nil)))
+ Some(map.entry(id.clone()).or_insert_with(|| Value::new(None, ValueKind::Nil)))
}
_ => None,
@@ -73,14 +73,14 @@ impl Expression {
Some(value) => {
match value.kind {
ValueKind::Table(ref mut map) => {
- Some(map.entry(key.clone()).or_insert(Value::new(None, ValueKind::Nil)))
+ Some(map.entry(key.clone()).or_insert_with(|| Value::new(None, ValueKind::Nil)))
}
_ => {
*value = HashMap::<String, Value>::new().into();
if let ValueKind::Table(ref mut map) = value.kind {
- Some(map.entry(key.clone()).or_insert(Value::new(None, ValueKind::Nil)))
+ Some(map.entry(key.clone()).or_insert_with(|| Value::new(None, ValueKind::Nil)))
} else {
println!("WHAT THE FUCK?");
@@ -116,7 +116,7 @@ impl Expression {
ValueKind::Table(ref incoming_map) => {
// Pull out another table
let mut target = if let ValueKind::Table(ref mut map) = root.kind {
- map.entry(id.clone()).or_insert(HashMap::<String, Value>::new().into())
+ map.entry(id.clone()).or_insert_with(|| HashMap::<String, Value>::new().into())
} else {
unreachable!();
};
diff --git a/src/path/parser.rs b/src/path/parser.rs
index eea4343..ee3fb65 100644
--- a/src/path/parser.rs
+++ b/src/path/parser.rs
@@ -28,8 +28,9 @@ named!(integer <i32>,
named!(ident<Expression>, map!(ident_, Expression::Identifier));
+#[allow(cyclomatic_complexity)]
fn postfix(expr: Expression) -> Box<Fn(&[u8]) -> IResult<&[u8], Expression>> {
- return Box::new(move |i: &[u8]| {
+ Box::new(move |i: &[u8]| {
alt!(i,
do_parse!(
tag!(".") >>
@@ -49,13 +50,13 @@ fn postfix(expr: Expression) -> Box<Fn(&[u8]) -> IResult<&[u8], Expression>> {
char!(']')
)
)
- });
+ })
}
pub fn from_str(input: &str) -> Result<Expression, ErrorKind> {
match ident(input.as_bytes()) {
IResult::Done(mut rem, mut expr) => {
- while rem.len() > 0 {
+ while !rem.is_empty() {
match postfix(expr)(rem) {
IResult::Done(rem_, expr_) => {
rem = rem_;
@@ -63,7 +64,7 @@ pub fn from_str(input: &str) -> Result<Expression, ErrorKind> {
}
// Forward Incomplete and Error
- result @ _ => {
+ result => {
return result.to_result();
}
}
@@ -73,7 +74,7 @@ pub fn from_str(input: &str) -> Result<Expression, ErrorKind> {
}
// Forward Incomplete and Error
- result @ _ => result.to_result(),
+ result => result.to_result(),
}
}