From d491d3765ccd99921cad9854e1061757e0883cc3 Mon Sep 17 00:00:00 2001 From: tomoikey <55743826+tomoikey@users.noreply.github.com> Date: Thu, 3 Oct 2024 05:31:36 +0900 Subject: [PATCH] add skip odd even --- src/rule/collection/skip/option.rs | 4 ++++ src/rule/collection/skip/option/skip_even_index.rs | 13 +++++++++++++ src/rule/collection/skip/option/skip_odd_index.rs | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/rule/collection/skip/option/skip_even_index.rs create mode 100644 src/rule/collection/skip/option/skip_odd_index.rs diff --git a/src/rule/collection/skip/option.rs b/src/rule/collection/skip/option.rs index 2e05b53..b551f16 100644 --- a/src/rule/collection/skip/option.rs +++ b/src/rule/collection/skip/option.rs @@ -1,8 +1,12 @@ mod no_skip; +mod skip_even_index; mod skip_first; +mod skip_odd_index; pub use no_skip::NoSkip; +pub use skip_even_index::SkipEvenIndex; pub use skip_first::SkipFirst; +pub use skip_odd_index::SkipOddIndex; pub trait SkipOption { type Item; diff --git a/src/rule/collection/skip/option/skip_even_index.rs b/src/rule/collection/skip/option/skip_even_index.rs new file mode 100644 index 0000000..44183b6 --- /dev/null +++ b/src/rule/collection/skip/option/skip_even_index.rs @@ -0,0 +1,13 @@ +use crate::rule::SkipOption; + +pub struct SkipEvenIndex { + _phantom_data: std::marker::PhantomData, +} + +impl SkipOption for SkipEvenIndex { + type Item = ITEM; + type Accumulator = (); + fn should_skip(i: usize, _: Option<&mut Self::Accumulator>, _: &Self::Item) -> bool { + i % 2 == 0 + } +} diff --git a/src/rule/collection/skip/option/skip_odd_index.rs b/src/rule/collection/skip/option/skip_odd_index.rs new file mode 100644 index 0000000..7a4b3ba --- /dev/null +++ b/src/rule/collection/skip/option/skip_odd_index.rs @@ -0,0 +1,13 @@ +use crate::rule::SkipOption; + +pub struct SkipOddIndex { + _phantom_data: std::marker::PhantomData, +} + +impl SkipOption for SkipOddIndex { + type Item = ITEM; + type Accumulator = (); + fn should_skip(i: usize, _: Option<&mut Self::Accumulator>, _: &Self::Item) -> bool { + i % 2 == 1 + } +}