mirror of
https://github.com/danog/strum.git
synced 2024-11-26 12:04:38 +01:00
Made a fix for #80
This commit is contained in:
parent
de17e1c7a2
commit
da37cc3141
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user