aoc_toolkit/core/
registry.rs1use crate::core::RegisteredDay;
2
3pub struct Registry {
4 groups: &'static [&'static [RegisteredDay]],
5}
6
7impl Registry {
8 #[must_use]
9 pub const fn new(groups: &'static [&'static [RegisteredDay]]) -> Self {
10 Self { groups }
11 }
12
13 pub fn iter(&self) -> impl Iterator<Item = &RegisteredDay> {
14 self.groups.iter().flat_map(|group| group.iter())
15 }
16
17 #[must_use]
18 pub fn find(&self, year: usize, day: usize) -> Option<&RegisteredDay> {
19 self.iter().find(|d| d.year == year && d.day == day)
20 }
21
22 #[must_use]
23 pub fn latest_year(&self) -> Option<usize> {
24 self.iter().map(|d| d.year).max()
25 }
26
27 #[must_use]
28 pub fn latest_day(&self, year: usize) -> Option<usize> {
29 self.iter().filter(|d| d.year == year).map(|d| d.day).max()
30 }
31
32 #[must_use]
33 pub fn latest(&self) -> Option<&RegisteredDay> {
34 self.iter().max_by_key(|d| (d.year, d.day))
35 }
36}