1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::field::ScalarFieldRef;

#[derive(Clone, PartialEq, Eq, Hash)]
pub enum ScalarProjection {
    /// A single field projection.
    Single(ScalarFieldRef),

    /// A tuple projection, e.g. if (a, b) <in> ((1, 2), (1, 3), ...) is supposed to be queried.
    Compound(Vec<ScalarFieldRef>),
}

impl std::fmt::Debug for ScalarProjection {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Single(sf) => f.debug_tuple("SingleProjection").field(&format!("{sf}")).finish(),
            Self::Compound(sfs) => {
                let mut dbg = f.debug_tuple("CompoundProjection");

                for sf in sfs {
                    dbg.field(&format!("{sf}"));
                }

                dbg.finish()
            }
        }
    }
}

impl ScalarProjection {
    pub fn scalar_fields(&self) -> Vec<&ScalarFieldRef> {
        match self {
            ScalarProjection::Single(sf) => vec![sf],
            ScalarProjection::Compound(sfs) => sfs.iter().collect(),
        }
    }

    pub fn as_single(&self) -> Option<&ScalarFieldRef> {
        match self {
            ScalarProjection::Single(sf) => Some(sf),
            ScalarProjection::Compound(_) => None,
        }
    }
}