Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
J-F-Liu committed Dec 7, 2018
1 parent 02a4ebb commit c1c6441
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fn(&'a [I], usize) -> Result<(O, usize)> + 'a>,
method: Box<Parse<'a, I, O>>,
}

impl<'a, I, O> Parser<'a, I, O> {
Expand Down Expand Up @@ -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()
})
}
Expand Down Expand Up @@ -174,7 +176,7 @@ impl<'a, I, O> Parser<'a, I, O> {
});
}
}
return Ok((items, pos));
Ok((items, pos))
})
}

Expand Down Expand Up @@ -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))
})
}

Expand Down Expand Up @@ -318,7 +320,7 @@ where
}
}
}
return Ok((items, pos));
Ok((items, pos))
})
}

Expand Down
12 changes: 6 additions & 6 deletions src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down

0 comments on commit c1c6441

Please sign in to comment.