MAINT: cargo fmt.

This commit is contained in:
Jeremy Wall 2018-09-03 00:06:15 -05:00
parent d24df3b852
commit 170e74209d
4 changed files with 27 additions and 40 deletions

View File

@ -1,8 +1,8 @@
//! Contains implementations of `InputIter`. //! Contains implementations of `InputIter`.
use std::iter::Iterator;
use std::fmt::Debug; use std::fmt::Debug;
use std::iter::Iterator;
use super::{Offsetable, InputIter}; use super::{InputIter, Offsetable};
/// Implements `InputIter` for any slice of T. /// Implements `InputIter` for any slice of T.
#[derive(Debug)] #[derive(Debug)]
@ -29,7 +29,7 @@ impl<'a, T: Debug + 'a> Iterator for SliceIter<'a, T> {
Some(item) => { Some(item) => {
self.offset += 1; self.offset += 1;
Some(item) Some(item)
}, }
None => None, None => None,
} }
} }
@ -50,4 +50,4 @@ impl<'a, T: Debug + 'a> Clone for SliceIter<'a, T> {
} }
} }
impl<'a, T: Debug + 'a> InputIter for SliceIter<'a, T> {} impl<'a, T: Debug + 'a> InputIter for SliceIter<'a, T> {}

View File

@ -1,6 +1,6 @@
//! A parser combinator library with a focus on fully abortable parsing and error handling. //! A parser combinator library with a focus on fully abortable parsing and error handling.
use std::iter::Iterator;
use std::fmt::Display; use std::fmt::Display;
use std::iter::Iterator;
pub trait Offsetable { pub trait Offsetable {
fn get_offset(&self) -> usize; fn get_offset(&self) -> usize;
@ -25,7 +25,7 @@ pub struct Error<E: Display> {
impl<E: Display> Error<E> { impl<E: Display> Error<E> {
// Constructs a new Error with an offset and no cause. // Constructs a new Error with an offset and no cause.
pub fn new<S: Offsetable>(err: E, offset: &S) -> Self { pub fn new<S: Offsetable>(err: E, offset: &S) -> Self {
Error{ Error {
err: err, err: err,
offset: offset.get_offset(), offset: offset.get_offset(),
cause: None, cause: None,
@ -34,7 +34,7 @@ impl<E: Display> Error<E> {
// Constructs a new Error with an offset and a cause. // Constructs a new Error with an offset and a cause.
pub fn caused_by<S: Offsetable>(err: E, offset: &S, cause: Self) -> Self { pub fn caused_by<S: Offsetable>(err: E, offset: &S, cause: Self) -> Self {
Error{ Error {
err: err, err: err,
offset: offset.get_offset(), offset: offset.get_offset(),
cause: Some(Box::new(cause)), cause: Some(Box::new(cause)),
@ -62,9 +62,7 @@ impl<E: Display> Display for Error<E> {
try!(write!(f, "{}", self.err)); try!(write!(f, "{}", self.err));
match self.cause { match self.cause {
Some(ref c) => write!(f, "\n\tCaused By:{}", c), Some(ref c) => write!(f, "\n\tCaused By:{}", c),
None => { None => Ok(()),
Ok(())
},
} }
} }
} }
@ -87,31 +85,31 @@ impl<I: InputIter, O, E: Display> Result<I, O, E> {
/// Returns true if the Result is Complete. /// Returns true if the Result is Complete.
pub fn is_complete(&self) -> bool { pub fn is_complete(&self) -> bool {
if let &Result::Complete(_, _) = self { if let &Result::Complete(_, _) = self {
return true; return true;
} }
return false; return false;
} }
/// Returns true if the Result is Incomoplete. /// Returns true if the Result is Incomoplete.
pub fn is_incomplete(&self) -> bool { pub fn is_incomplete(&self) -> bool {
if let &Result::Incomplete(_) = self { if let &Result::Incomplete(_) = self {
return true; return true;
} }
return false; return false;
} }
/// Returns true if the Result is Fail. /// Returns true if the Result is Fail.
pub fn is_fail(&self) -> bool { pub fn is_fail(&self) -> bool {
if let &Result::Fail(_) = self { if let &Result::Fail(_) = self {
return true; return true;
} }
return false; return false;
} }
/// Returns true if the Result is Abort. /// Returns true if the Result is Abort.
pub fn is_abort(&self) -> bool { pub fn is_abort(&self) -> bool {
if let &Result::Abort(_) = self { if let &Result::Abort(_) = self {
return true; return true;
} }
return false; return false;
} }
@ -124,4 +122,4 @@ pub mod macros;
pub mod iter; pub mod iter;
#[cfg(test)] #[cfg(test)]
mod test; mod test;

View File

@ -289,4 +289,4 @@ macro_rules! repeat {
($i:expr, $f:ident) => { ($i:expr, $f:ident) => {
repeat!($i, run!($f)) repeat!($i, run!($f))
}; };
} }

View File

@ -1,5 +1,5 @@
use super::iter::SliceIter; use super::iter::SliceIter;
use super::{Result, Offsetable}; use super::{Offsetable, Result};
#[test] #[test]
fn test_slice_iter() { fn test_slice_iter() {
@ -20,7 +20,7 @@ fn test_slice_iter() {
assert_eq!('o' as u8, out[1]); assert_eq!('o' as u8, out[1]);
assert_eq!('o' as u8, out[2]); assert_eq!('o' as u8, out[2]);
assert_eq!(3, iter.get_offset()); assert_eq!(3, iter.get_offset());
out = Vec::new(); out = Vec::new();
for b in cloned { for b in cloned {
out.push(b.clone()); out.push(b.clone());
@ -31,7 +31,7 @@ fn test_slice_iter() {
assert_eq!('o' as u8, out[2]); assert_eq!('o' as u8, out[2]);
} }
fn will_fail(i: SliceIter<u8>) -> Result<SliceIter<u8>, String, String> { fn will_fail(i: SliceIter<u8>) -> Result<SliceIter<u8>, String, String> {
Result::Fail(super::Error::new("AAAAHHH!!!".to_string(), &i)) Result::Fail(super::Error::new("AAAAHHH!!!".to_string(), &i))
} }
@ -172,10 +172,7 @@ fn test_do_each() {
fn test_either_idents() { fn test_either_idents() {
let input_str = "foo"; let input_str = "foo";
let iter = SliceIter::new(input_str.as_bytes()); let iter = SliceIter::new(input_str.as_bytes());
let result = either!(iter, let result = either!(iter, will_fail, will_fail, parse_three);
will_fail,
will_fail,
parse_three);
assert!(result.is_complete()); assert!(result.is_complete());
if let Result::Complete(_, o) = result { if let Result::Complete(_, o) = result {
assert_eq!("foo".to_string(), o); assert_eq!("foo".to_string(), o);
@ -188,10 +185,7 @@ fn test_either_idents() {
fn test_either_macros() { fn test_either_macros() {
let input_str = "foo"; let input_str = "foo";
let iter = SliceIter::new(input_str.as_bytes()); let iter = SliceIter::new(input_str.as_bytes());
let result = either!(iter, let result = either!(iter, run!(will_fail), run!(will_fail), run!(parse_three));
run!(will_fail),
run!(will_fail),
run!(parse_three));
assert!(result.is_complete()); assert!(result.is_complete());
if let Result::Complete(_, o) = result { if let Result::Complete(_, o) = result {
assert_eq!("foo".to_string(), o); assert_eq!("foo".to_string(), o);
@ -204,9 +198,7 @@ fn test_either_macros() {
fn test_either_fail() { fn test_either_fail() {
let input_str = "foo"; let input_str = "foo";
let iter = SliceIter::new(input_str.as_bytes()); let iter = SliceIter::new(input_str.as_bytes());
let result = either!(iter, let result = either!(iter, run!(will_fail), run!(will_fail));
run!(will_fail),
run!(will_fail));
assert!(result.is_fail()); assert!(result.is_fail());
} }
@ -214,10 +206,7 @@ fn test_either_fail() {
fn test_either_abort() { fn test_either_abort() {
let input_str = "foo"; let input_str = "foo";
let iter = SliceIter::new(input_str.as_bytes()); let iter = SliceIter::new(input_str.as_bytes());
let result = either!(iter, let result = either!(iter, must!(will_fail), parse_three, run!(will_fail));
must!(will_fail),
parse_three,
run!(will_fail));
assert!(result.is_abort()); assert!(result.is_abort());
} }
@ -290,4 +279,4 @@ fn test_repeat_abort() {
let iter = SliceIter::new(input_str.as_bytes()); let iter = SliceIter::new(input_str.as_bytes());
let result = repeat!(iter, must!(will_fail)); let result = repeat!(iter, must!(will_fail));
assert!(result.is_abort()); assert!(result.is_abort());
} }