Skip to content

Commit

Permalink
Made a fix for Peternator7#80
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-glotfelty committed Mar 1, 2020
1 parent de17e1c commit da37cc3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extensions": [
"rust-lang.rust",
"webfreak.debug"
"webfreak.debug",
"matklad.rust-analyzer"
],
"workspaceFolder": "strum",
"postCreateCommand": "curl --proto '=https' --tlsv1.2 -sSf -o ~/rustup.sh https://sh.rustup.rs && /bin/bash ~/rustup.sh -y",
Expand Down
18 changes: 9 additions & 9 deletions strum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ impl std::error::Error for ParseError {
/// Yellow,
/// }
///
/// // Iterating over any enum requires 2 type parameters
/// // A 3rd is used in this example to allow passing a predicate
/// fn generic_iterator<E, I, F>(pred: F)
/// where E: IntoEnumIterator<Iterator=I>,
/// I: Iterator<Item=E>,
/// F: Fn(E) {
/// // Iterate over the items in an enum and perform some function on them.
/// fn generic_iterator<E, F>(pred: F)
/// where
/// E: IntoEnumIterator,
/// F: Fn(E),
/// {
/// for e in E::iter() {
/// pred(e)
/// }
/// }
///
/// fn main() {
/// generic_iterator::<Color,_, _>(|color| println!("{:?}", color));
/// generic_iterator::<Color, _>(|color| println!("{:?}", color));
/// }
/// ```
pub trait IntoEnumIterator {
type Iterator;
pub trait IntoEnumIterator: Sized {
type Iterator: Iterator<Item = Self>;

fn iter() -> Self::Iterator;
}
Expand Down
2 changes: 1 addition & 1 deletion strum_tests/tests/enum_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ fn take_nth_test() {
assert_eq!(None, iter.nth(1));
assert_eq!(None, iter.next());
assert_eq!(None, iter.next_back());
}
}
5 changes: 4 additions & 1 deletion strum_tests/tests/enum_variant_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ fn plain_kebab() {
RebeccaPurple,
}

assert_eq!(Color::VARIANTS, &["red", "blue", "yellow", "rebecca-purple"]);
assert_eq!(
Color::VARIANTS,
&["red", "blue", "yellow", "rebecca-purple"]
);
}

#[test]
Expand Down

0 comments on commit da37cc3

Please sign in to comment.