-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved various function signatures, added macro
- Loading branch information
1 parent
88376f5
commit 2b135c9
Showing
4 changed files
with
60 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
|
||
/// A macro used to simplify chaining together multiple `IntoIter` types. | ||
/// | ||
/// Returns a single iterator yielding all of the chained elements. | ||
#[macro_export] | ||
macro_rules! chain { | ||
() => { ::std::iter::empty() }; | ||
($first: expr) => { $first.into_iter() }; | ||
($first: expr, $($iter:expr),*) => { $first.into_iter()$(.chain($iter))* }; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ pub use vec::{ | |
TakeOnly, | ||
}; | ||
|
||
mod chain; | ||
pub mod epsilon; | ||
pub mod factorisation; | ||
pub mod fps; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#[macro_use] extern crate utils; | ||
|
||
#[test] | ||
fn chain() { | ||
|
||
let empty: ::std::iter::Empty<i32> = chain![]; | ||
let empty_vec: Vec<i32> = vec![]; | ||
assert_eq!(empty.collect::<Vec<_>>(), empty_vec); | ||
|
||
let one = chain![Some("G'day")]; | ||
assert_eq!(one.collect::<Vec<_>>(), vec!["G'day"]); | ||
|
||
let nums = chain![Some(0), vec![1, 2, 3, 4], Some(5).into_iter().chain(Some(6))]; | ||
assert_eq!(nums.collect::<Vec<_>>(), vec![0, 1, 2, 3, 4, 5, 6]); | ||
|
||
} | ||
|