From 170e74209da583c10e3056c52294ae48533e0eca Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Mon, 3 Sep 2018 00:06:15 -0500 Subject: [PATCH] MAINT: cargo fmt. --- src/iter.rs | 8 ++++---- src/lib.rs | 30 ++++++++++++++---------------- src/macros.rs | 2 +- src/test.rs | 27 ++++++++------------------- 4 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/iter.rs b/src/iter.rs index b8eac17..6765749 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -1,8 +1,8 @@ //! Contains implementations of `InputIter`. -use std::iter::Iterator; use std::fmt::Debug; +use std::iter::Iterator; -use super::{Offsetable, InputIter}; +use super::{InputIter, Offsetable}; /// Implements `InputIter` for any slice of T. #[derive(Debug)] @@ -29,7 +29,7 @@ impl<'a, T: Debug + 'a> Iterator for SliceIter<'a, T> { Some(item) => { self.offset += 1; Some(item) - }, + } 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> {} \ No newline at end of file +impl<'a, T: Debug + 'a> InputIter for SliceIter<'a, T> {} diff --git a/src/lib.rs b/src/lib.rs index c6cd520..71e2683 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ //! A parser combinator library with a focus on fully abortable parsing and error handling. -use std::iter::Iterator; use std::fmt::Display; +use std::iter::Iterator; pub trait Offsetable { fn get_offset(&self) -> usize; @@ -25,7 +25,7 @@ pub struct Error { impl Error { // Constructs a new Error with an offset and no cause. pub fn new(err: E, offset: &S) -> Self { - Error{ + Error { err: err, offset: offset.get_offset(), cause: None, @@ -34,7 +34,7 @@ impl Error { // Constructs a new Error with an offset and a cause. pub fn caused_by(err: E, offset: &S, cause: Self) -> Self { - Error{ + Error { err: err, offset: offset.get_offset(), cause: Some(Box::new(cause)), @@ -62,9 +62,7 @@ impl Display for Error { try!(write!(f, "{}", self.err)); match self.cause { Some(ref c) => write!(f, "\n\tCaused By:{}", c), - None => { - Ok(()) - }, + None => Ok(()), } } } @@ -87,31 +85,31 @@ impl Result { /// Returns true if the Result is Complete. pub fn is_complete(&self) -> bool { if let &Result::Complete(_, _) = self { - return true; + return true; } return false; } - /// Returns true if the Result is Incomoplete. + /// Returns true if the Result is Incomoplete. pub fn is_incomplete(&self) -> bool { if let &Result::Incomplete(_) = self { - return true; + return true; } return false; } - - /// Returns true if the Result is Fail. + + /// Returns true if the Result is Fail. pub fn is_fail(&self) -> bool { if let &Result::Fail(_) = self { - return true; + return true; } return false; } - - /// Returns true if the Result is Abort. + + /// Returns true if the Result is Abort. pub fn is_abort(&self) -> bool { if let &Result::Abort(_) = self { - return true; + return true; } return false; } @@ -124,4 +122,4 @@ pub mod macros; pub mod iter; #[cfg(test)] -mod test; \ No newline at end of file +mod test; diff --git a/src/macros.rs b/src/macros.rs index 08488e5..8f96cc5 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -289,4 +289,4 @@ macro_rules! repeat { ($i:expr, $f:ident) => { repeat!($i, run!($f)) }; -} \ No newline at end of file +} diff --git a/src/test.rs b/src/test.rs index 6b9f567..5b74f6a 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,5 +1,5 @@ use super::iter::SliceIter; -use super::{Result, Offsetable}; +use super::{Offsetable, Result}; #[test] 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[2]); assert_eq!(3, iter.get_offset()); - + out = Vec::new(); for b in cloned { out.push(b.clone()); @@ -31,7 +31,7 @@ fn test_slice_iter() { assert_eq!('o' as u8, out[2]); } -fn will_fail(i: SliceIter) -> Result, String, String> { +fn will_fail(i: SliceIter) -> Result, String, String> { Result::Fail(super::Error::new("AAAAHHH!!!".to_string(), &i)) } @@ -172,10 +172,7 @@ fn test_do_each() { fn test_either_idents() { let input_str = "foo"; let iter = SliceIter::new(input_str.as_bytes()); - let result = either!(iter, - will_fail, - will_fail, - parse_three); + let result = either!(iter, will_fail, will_fail, parse_three); assert!(result.is_complete()); if let Result::Complete(_, o) = result { assert_eq!("foo".to_string(), o); @@ -188,10 +185,7 @@ fn test_either_idents() { fn test_either_macros() { let input_str = "foo"; let iter = SliceIter::new(input_str.as_bytes()); - let result = either!(iter, - run!(will_fail), - run!(will_fail), - run!(parse_three)); + let result = either!(iter, run!(will_fail), run!(will_fail), run!(parse_three)); assert!(result.is_complete()); if let Result::Complete(_, o) = result { assert_eq!("foo".to_string(), o); @@ -204,9 +198,7 @@ fn test_either_macros() { fn test_either_fail() { let input_str = "foo"; let iter = SliceIter::new(input_str.as_bytes()); - let result = either!(iter, - run!(will_fail), - run!(will_fail)); + let result = either!(iter, run!(will_fail), run!(will_fail)); assert!(result.is_fail()); } @@ -214,10 +206,7 @@ fn test_either_fail() { fn test_either_abort() { let input_str = "foo"; let iter = SliceIter::new(input_str.as_bytes()); - let result = either!(iter, - must!(will_fail), - parse_three, - run!(will_fail)); + let result = either!(iter, must!(will_fail), parse_three, run!(will_fail)); assert!(result.is_abort()); } @@ -290,4 +279,4 @@ fn test_repeat_abort() { let iter = SliceIter::new(input_str.as_bytes()); let result = repeat!(iter, must!(will_fail)); assert!(result.is_abort()); -} \ No newline at end of file +}