Skip to main content

dbkit_core/
load.rs

1#[derive(Debug, Clone, Copy)]
2pub struct NoLoad;
3
4#[derive(Debug, Clone, Copy)]
5pub struct LoadChain<Prev, L> {
6    pub prev: Prev,
7    pub load: L,
8}
9
10pub trait ApplyLoad<Out> {
11    type Out2;
12}
13
14impl<Out> ApplyLoad<Out> for NoLoad {
15    type Out2 = Out;
16}
17
18impl<Out, Prev, L> ApplyLoad<Out> for LoadChain<Prev, L>
19where
20    Prev: ApplyLoad<Out>,
21    L: ApplyLoad<Prev::Out2>,
22{
23    type Out2 = <L as ApplyLoad<Prev::Out2>>::Out2;
24}
25
26#[derive(Debug, Clone, Copy)]
27pub struct SelectIn<R, Nested = NoLoad> {
28    pub rel: R,
29    pub nested: Nested,
30}
31
32impl<R> SelectIn<R, NoLoad> {
33    pub fn new(rel: R) -> Self {
34        Self { rel, nested: NoLoad }
35    }
36}
37
38impl<R, Nested> SelectIn<R, Nested> {
39    pub fn with<L>(self, load: L) -> SelectIn<R, LoadChain<Nested, L>> {
40        SelectIn {
41            rel: self.rel,
42            nested: LoadChain { prev: self.nested, load },
43        }
44    }
45}
46
47#[derive(Debug, Clone, Copy)]
48pub struct Joined<R, Nested = NoLoad> {
49    pub rel: R,
50    pub nested: Nested,
51}
52
53impl<R> Joined<R, NoLoad> {
54    pub fn new(rel: R) -> Self {
55        Self { rel, nested: NoLoad }
56    }
57}
58
59impl<R, Nested> Joined<R, Nested> {
60    pub fn with<L>(self, load: L) -> Joined<R, LoadChain<Nested, L>> {
61        Joined {
62            rel: self.rel,
63            nested: LoadChain { prev: self.nested, load },
64        }
65    }
66}