| 1 |
//! A simple implementation of peano numbers. |
| 2 |
//! |
| 3 |
//! This is used to enforce that columns can only be selected from a given from |
| 4 |
//! clause if their table appears exactly one time. |
| 5 |
|
| 6 |
/// A table never appears in the from clause. |
| 7 |
#[allow(missing_debug_implementations, missing_copy_implementations)] |
| 8 |
pub struct Never; |
| 9 |
|
| 10 |
/// A table appears in the from clause exactly one time. |
| 11 |
#[allow(missing_debug_implementations, missing_copy_implementations)] |
| 12 |
pub struct Once; |
| 13 |
|
| 14 |
/// A table appears in the from clause two or more times. |
| 15 |
#[allow(missing_debug_implementations, missing_copy_implementations)] |
| 16 |
pub struct MoreThanOnce; |
| 17 |
|
| 18 |
/// Add two peano numbers together. |
| 19 |
/// |
| 20 |
/// This is used to determine the number of times a table appears in a from |
| 21 |
/// clause when the from clause contains a join. |
| 22 |
pub trait Plus<T> { |
| 23 |
/// The result of adding these numbers together |
| 24 |
type Output; |
| 25 |
} |
| 26 |
|
| 27 |
impl<T> Plus<T> for Never { |
| 28 |
type Output = T; |
| 29 |
} |
| 30 |
|
| 31 |
impl<T> Plus<T> for MoreThanOnce { |
| 32 |
type Output = Self; |
| 33 |
} |
| 34 |
|
| 35 |
impl Plus<Never> for Once { |
| 36 |
type Output = Self; |
| 37 |
} |
| 38 |
|
| 39 |
impl Plus<Once> for Once { |
| 40 |
type Output = MoreThanOnce; |
| 41 |
} |
| 42 |
|
| 43 |
impl Plus<MoreThanOnce> for Once { |
| 44 |
type Output = MoreThanOnce; |
| 45 |
} |