codesort/
gifts.rs

1// TODO try to explain how and why this works without sounding too crazy
2
3#[derive(Debug, Clone)]
4pub struct CharSet {
5    pub chars: Vec<char>,
6}
7impl From<char> for CharSet {
8    fn from(c: char) -> Self {
9        CharSet { chars: vec![c] }
10    }
11}
12impl From<Vec<char>> for CharSet {
13    fn from(chars: Vec<char>) -> Self {
14        CharSet { chars }
15    }
16}
17
18/// Something that is required by the state of a LOC list
19#[derive(Debug, Clone)]
20pub struct Wish {
21    pub any_of: CharSet,
22    pub depth: usize,
23}
24
25/// Something that can maybe satisfy a wish
26#[derive(Debug, Clone, Copy)]
27pub struct Gift {
28    pub depth: usize,
29    pub c: char,
30}
31
32impl Gift {
33    pub fn satisfies(
34        &self,
35        wish: &Wish,
36    ) -> bool {
37        wish.depth == self.depth && wish.any_of.chars.contains(&self.c)
38    }
39}