From da37cc3141ab668f0d1a3ff86532b50a071c304c Mon Sep 17 00:00:00 2001 From: root Date: Sun, 1 Mar 2020 23:55:53 +0000 Subject: [PATCH] Made a fix for #80 --- .devcontainer/devcontainer.json | 3 ++- strum/src/lib.rs | 18 +++++++++--------- strum_tests/tests/enum_iter.rs | 2 +- strum_tests/tests/enum_variant_names.rs | 5 ++++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3561579..b681787 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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", diff --git a/strum/src/lib.rs b/strum/src/lib.rs index fc78913..ab37d11 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -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(pred: F) -/// where E: IntoEnumIterator, -/// I: Iterator, -/// F: Fn(E) { +/// // Iterate over the items in an enum and perform some function on them. +/// fn generic_iterator(pred: F) +/// where +/// E: IntoEnumIterator, +/// F: Fn(E), +/// { /// for e in E::iter() { /// pred(e) /// } /// } /// /// fn main() { -/// generic_iterator::(|color| println!("{:?}", color)); +/// generic_iterator::(|color| println!("{:?}", color)); /// } /// ``` -pub trait IntoEnumIterator { - type Iterator; +pub trait IntoEnumIterator: Sized { + type Iterator: Iterator; fn iter() -> Self::Iterator; } diff --git a/strum_tests/tests/enum_iter.rs b/strum_tests/tests/enum_iter.rs index 6e1975e..72dbbb2 100644 --- a/strum_tests/tests/enum_iter.rs +++ b/strum_tests/tests/enum_iter.rs @@ -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()); -} \ No newline at end of file +} diff --git a/strum_tests/tests/enum_variant_names.rs b/strum_tests/tests/enum_variant_names.rs index 37d8758..2b5b059 100644 --- a/strum_tests/tests/enum_variant_names.rs +++ b/strum_tests/tests/enum_variant_names.rs @@ -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]