Skip to content

Commit e0c88c8

Browse files
committed
chore: avoid using Deref
1 parent bab4c2c commit e0c88c8

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
use std::cmp::{max, min};
2-
use std::ops::{Deref, RangeInclusive};
2+
use std::ops::RangeInclusive;
33
use std::str::FromStr;
44

5-
use aoclp::functional::ByRefPredHelper;
65
use aoclp::solvers_impl::input::safe_get_input_as_many_of_two_types;
76
use itertools::Itertools;
87

98
pub fn part_1() -> usize {
109
let (fresh_ids, available_ids) = input();
1110
available_ids
1211
.into_iter()
13-
.filter(|&id| fresh_ids.iter().any(|r| r.contains(&id)))
12+
.filter(|&id| fresh_ids.iter().any(|r| r.0.contains(&id)))
1413
.count()
1514
}
1615

1716
pub fn part_2() -> usize {
1817
let (fresh_ids, _) = input();
1918
fresh_ids
2019
.into_iter()
20+
.map(|r| r.0)
2121
.sorted_by(|a, b| a.start().cmp(b.start()).then(a.end().cmp(b.end())))
2222
.fold(Vec::new(), |mut acc, r| {
2323
match acc.last() {
@@ -27,14 +27,14 @@ pub fn part_2() -> usize {
2727
let from = *min(prev.start(), r.start());
2828
let to = *max(prev.end(), r.end());
2929
acc.pop();
30-
acc.push(IdRange(from..=to));
30+
acc.push(from..=to);
3131
},
3232
}
3333

3434
acc
3535
})
3636
.into_iter()
37-
.map(IdRange::len.without_ref())
37+
.map(|r| r.count())
3838
.sum()
3939
}
4040

@@ -43,7 +43,7 @@ struct IdRange(RangeInclusive<usize>);
4343

4444
impl IdRange {
4545
pub fn len(&self) -> usize {
46-
self.end() - self.start() + 1
46+
self.0.end() - self.0.start() + 1
4747
}
4848
}
4949

@@ -57,14 +57,6 @@ impl FromStr for IdRange {
5757
}
5858
}
5959

60-
impl Deref for IdRange {
61-
type Target = RangeInclusive<usize>;
62-
63-
fn deref(&self) -> &Self::Target {
64-
&self.0
65-
}
66-
}
67-
6860
fn input() -> (Vec<IdRange>, Vec<usize>) {
6961
safe_get_input_as_many_of_two_types(2025, 5)
7062
}

0 commit comments

Comments
 (0)