Skip to content

Commit 19f3cc2

Browse files
authored
Merge pull request #31 from tomoikey/feat/refactoring
remove lifetime parameter
2 parents cd2a9a5 + 1f7378b commit 19f3cc2

File tree

6 files changed

+58
-52
lines changed

6 files changed

+58
-52
lines changed

src/rule/collection/exists.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::collections::{HashMap, HashSet, VecDeque};
22

33
use crate::rule::composer::Not;
4-
use crate::rule::{ForAllRule, Rule};
4+
use crate::rule::{ForAllRule, Iterable, Rule};
55
use crate::Refined;
66

77
/// A type that holds a value satisfying the `ExistsRule`
8-
pub type Exists<RULE, ITERABLE> = Refined<ExistsRule<RULE, ITERABLE, <RULE as Rule>::Item>>;
8+
pub type Exists<RULE, ITERABLE> = Refined<ExistsRule<RULE, ITERABLE>>;
99

1010
/// A type that holds a Vec value satisfying the `ExistsRule`
1111
pub type ExistsVec<RULE> = Refined<ExistsVecRule<RULE>>;
@@ -23,25 +23,23 @@ pub type ExistsHashMap<K, RULE> = Refined<ExistsHashMapRule<K, RULE>>;
2323
pub type ExistsString<RULE> = Refined<ExistsStringRule<RULE>>;
2424

2525
/// Rule where at least one data in the collection satisfies the condition
26-
pub type ExistsRule<RULE, ITERABLE, ITEM> = Not<ForAllRule<Not<RULE>, ITERABLE, ITEM>>;
26+
pub type ExistsRule<RULE, ITERABLE> =
27+
Not<ForAllRule<Not<RULE>, ITERABLE, <ITERABLE as Iterable>::Item>>;
2728

2829
/// Rule where at least one data in the `Vec` satisfies the condition
29-
pub type ExistsVecRule<RULE> = ExistsRule<RULE, Vec<<RULE as Rule>::Item>, <RULE as Rule>::Item>;
30+
pub type ExistsVecRule<RULE> = ExistsRule<RULE, Vec<<RULE as Rule>::Item>>;
3031

3132
/// Rule where at least one data in the `VecDeque` satisfies the condition
32-
pub type ExistsVecDequeRule<RULE> =
33-
ExistsRule<RULE, VecDeque<<RULE as Rule>::Item>, <RULE as Rule>::Item>;
33+
pub type ExistsVecDequeRule<RULE> = ExistsRule<RULE, VecDeque<<RULE as Rule>::Item>>;
3434

3535
/// Rule where at least one data in the `HashSet` satisfies the condition
36-
pub type ExistsHashSetRule<RULE> =
37-
ExistsRule<RULE, HashSet<<RULE as Rule>::Item>, <RULE as Rule>::Item>;
36+
pub type ExistsHashSetRule<RULE> = ExistsRule<RULE, HashSet<<RULE as Rule>::Item>>;
3837

3938
/// Rule where at least one data in the `HashMap` satisfies the condition
40-
pub type ExistsHashMapRule<K, RULE> =
41-
ExistsRule<RULE, HashMap<K, <RULE as Rule>::Item>, <RULE as Rule>::Item>;
39+
pub type ExistsHashMapRule<K, RULE> = ExistsRule<RULE, HashMap<K, <RULE as Rule>::Item>>;
4240

4341
/// Rule where at least one data in the `String` satisfies the condition
44-
pub type ExistsStringRule<RULE> = ExistsRule<RULE, String, char>;
42+
pub type ExistsStringRule<RULE> = ExistsRule<RULE, String>;
4543

4644
#[cfg(test)]
4745
mod tests {

src/rule/collection/init.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ use crate::Refined;
33
use std::collections::VecDeque;
44

55
/// A type that holds a value satisfying the `InitRule`
6-
pub type Init<'a, RULE, ITERABLE> = Refined<InitRule<'a, RULE, ITERABLE>>;
6+
pub type Init<'a, RULE, ITERABLE> = Refined<InitRule<RULE, ITERABLE>>;
77

88
/// A type that holds a Vec value satisfying the `InitRule`
9-
pub type InitVec<'a, RULE> = Refined<InitVecRule<'a, RULE>>;
9+
pub type InitVec<RULE> = Refined<InitVecRule<RULE>>;
1010

1111
/// A type that holds a VecDeque value satisfying the `InitRule`
12-
pub type InitVecDeque<'a, RULE> = Refined<InitVecDequeRule<'a, RULE>>;
12+
pub type InitVecDeque<RULE> = Refined<InitVecDequeRule<RULE>>;
1313

1414
/// A type that holds a String value satisfying the `InitRule`
15-
pub type InitString<'a, RULE> = Refined<InitStringRule<'a, RULE>>;
15+
pub type InitString<'a, RULE> = Refined<InitStringRule<RULE>>;
1616

1717
/// Rule that applies to the initialization of a collection
18-
pub type InitRule<'a, RULE, ITERABLE> =
19-
ReverseRule<'a, SkipRule<RULE, ITERABLE, SkipFirst<<ITERABLE as Iterable<'a>>::Item>>>;
18+
pub type InitRule<RULE, ITERABLE> =
19+
ReverseRule<SkipRule<RULE, ITERABLE, SkipFirst<<ITERABLE as Iterable>::Item>>>;
2020

2121
/// Rule that applies to the initialization of a `Vec`
22-
pub type InitVecRule<'a, RULE> = InitRule<'a, RULE, Vec<<RULE as Rule>::Item>>;
22+
pub type InitVecRule<RULE> = InitRule<RULE, Vec<<RULE as Rule>::Item>>;
2323

2424
/// Rule that applies to the initialization of a `VecDeque`
25-
pub type InitVecDequeRule<'a, RULE> = InitRule<'a, RULE, VecDeque<<RULE as Rule>::Item>>;
25+
pub type InitVecDequeRule<RULE> = InitRule<RULE, VecDeque<<RULE as Rule>::Item>>;
2626

2727
/// Rule that applies to the initialization of a `String`
28-
pub type InitStringRule<'a, RULE> = InitRule<'a, RULE, String>;
28+
pub type InitStringRule<RULE> = InitRule<RULE, String>;
2929

3030
#[cfg(test)]
3131
mod tests {

src/rule/collection/iterable.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
use std::collections::VecDeque;
22

3-
pub trait Iterable<'a> {
4-
type Item: 'a;
3+
pub trait Iterable {
4+
type Item;
55

6-
fn into_iterator(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a>;
6+
fn into_iterator<'a>(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a>
7+
where
8+
Self: 'a;
79
fn length(&self) -> usize;
810
}
911

10-
impl<'a, T> Iterable<'a> for Vec<T>
11-
where
12-
T: 'a,
13-
{
12+
impl<T> Iterable for Vec<T> {
1413
type Item = T;
1514

16-
fn into_iterator(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a> {
15+
fn into_iterator<'a>(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a>
16+
where
17+
Self: 'a,
18+
{
1719
Box::new(self.into_iter())
1820
}
1921

@@ -22,13 +24,13 @@ where
2224
}
2325
}
2426

25-
impl<'a, T> Iterable<'a> for VecDeque<T>
26-
where
27-
T: 'a,
28-
{
27+
impl<T> Iterable for VecDeque<T> {
2928
type Item = T;
3029

31-
fn into_iterator(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a> {
30+
fn into_iterator<'a>(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a>
31+
where
32+
Self: 'a,
33+
{
3234
Box::new(self.into_iter())
3335
}
3436

@@ -37,10 +39,13 @@ where
3739
}
3840
}
3941

40-
impl<'a> Iterable<'a> for String {
42+
impl Iterable for String {
4143
type Item = char;
4244

43-
fn into_iterator(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a> {
45+
fn into_iterator<'a>(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a>
46+
where
47+
Self: 'a,
48+
{
4449
Box::new(self.chars().collect::<Vec<_>>().into_iter())
4550
}
4651

@@ -49,10 +54,13 @@ impl<'a> Iterable<'a> for String {
4954
}
5055
}
5156

52-
impl<'a> Iterable<'a> for &'a str {
57+
impl<'a> Iterable for &'a str {
5358
type Item = char;
5459

55-
fn into_iterator(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'a> {
60+
fn into_iterator<'b>(self) -> Box<dyn DoubleEndedIterator<Item = Self::Item> + 'b>
61+
where
62+
Self: 'b,
63+
{
5664
Box::new(self.chars())
5765
}
5866

src/rule/collection/last.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ use crate::rule::{IndexRule, ReverseRule, Rule};
44
use crate::Refined;
55

66
/// A type that holds a value satisfying the `LastRule`
7-
pub type Last<'a, RULE, ITERABLE> = Refined<LastRule<'a, RULE, ITERABLE>>;
7+
pub type Last<RULE, ITERABLE> = Refined<LastRule<RULE, ITERABLE>>;
88

99
/// A type that holds a Vec value satisfying the `LastRule`
10-
pub type LastVec<'a, RULE> = Refined<LastVecRule<'a, RULE>>;
10+
pub type LastVec<RULE> = Refined<LastVecRule<RULE>>;
1111

1212
/// A type that holds a VecDeque value satisfying the `LastRule`
13-
pub type LastVecDeque<'a, RULE> = Refined<LastVecDequeRule<'a, RULE>>;
13+
pub type LastVecDeque<RULE> = Refined<LastVecDequeRule<RULE>>;
1414

1515
/// A type that holds a String value satisfying the `LastRule`
16-
pub type LastString<'a, RULE> = Refined<LastStringRule<'a, RULE>>;
16+
pub type LastString<RULE> = Refined<LastStringRule<RULE>>;
1717

1818
/// Rule where the last element satisfies the condition
19-
pub type LastRule<'a, RULE, ITERABLE> = ReverseRule<'a, IndexRule<0, RULE, ITERABLE>>;
19+
pub type LastRule<RULE, ITERABLE> = ReverseRule<IndexRule<0, RULE, ITERABLE>>;
2020

2121
/// Rule where the last element in the `Vec` satisfies the condition
22-
pub type LastVecRule<'a, RULE> = LastRule<'a, RULE, Vec<<RULE as Rule>::Item>>;
22+
pub type LastVecRule<RULE> = LastRule<RULE, Vec<<RULE as Rule>::Item>>;
2323

2424
/// Rule where the last element in the `VecDeque` satisfies the condition
25-
pub type LastVecDequeRule<'a, RULE> = LastRule<'a, RULE, VecDeque<<RULE as Rule>::Item>>;
25+
pub type LastVecDequeRule<RULE> = LastRule<RULE, VecDeque<<RULE as Rule>::Item>>;
2626

2727
/// Rule where the last element in the `String` satisfies the condition
28-
pub type LastStringRule<'a, RULE> = LastRule<'a, RULE, String>;
28+
pub type LastStringRule<RULE> = LastRule<RULE, String>;
2929

3030
#[cfg(test)]
3131
mod tests {

src/rule/collection/reverse.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ use crate::Refined;
44
use std::marker::PhantomData;
55

66
/// A type that holds a value satisfying the `ReverseRule`
7-
pub type Reverse<'a, RULE> = Refined<ReverseRule<'a, RULE>>;
7+
pub type Reverse<'a, RULE> = Refined<ReverseRule<RULE>>;
88

99
/// Rule where the data in the collection satisfies the condition after reversing
10-
pub struct ReverseRule<'a, RULE>
10+
pub struct ReverseRule<RULE>
1111
where
1212
RULE: Rule,
1313
{
14-
_phantom_data: PhantomData<&'a RULE>,
14+
_phantom_data: PhantomData<RULE>,
1515
}
1616

17-
impl<'a, RULE, ITERABLE> Rule for ReverseRule<'a, RULE>
17+
impl<RULE, ITERABLE> Rule for ReverseRule<RULE>
1818
where
1919
RULE: Rule<Item = ITERABLE>,
20-
ITERABLE: Iterable<'a> + FromIterator<ITERABLE::Item>,
20+
ITERABLE: Iterable + FromIterator<ITERABLE::Item>,
2121
{
2222
type Item = RULE::Item;
2323

src/rule/collection/skip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ where
2929
_phantom_data: PhantomData<(RULE, ITERABLE, OPTION)>,
3030
}
3131

32-
impl<'a, RULE, ITERABLE, OPTION> Rule for SkipRule<RULE, ITERABLE, OPTION>
32+
impl<RULE, ITERABLE, OPTION> Rule for SkipRule<RULE, ITERABLE, OPTION>
3333
where
3434
RULE: Rule,
35-
ITERABLE: Iterable<'a, Item = RULE::Item> + FromIterator<RULE::Item>,
35+
ITERABLE: Iterable<Item = RULE::Item> + FromIterator<RULE::Item>,
3636
OPTION: SkipOption<Item = RULE::Item>,
3737
{
3838
type Item = ITERABLE;

0 commit comments

Comments
 (0)