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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Arithmetic operators in logic

use crate::*;

/// Trait for addition (`+`) in logic code.
#[diagnostic::on_unimplemented(
    message = "Cannot add `{Rhs}` to `{Self}` in logic",
    label = "no implementation for `{Self} + {Rhs}` in logic"
)]
pub trait AddLogic<Rhs = Self> {
    type Output;

    #[logic]
    fn add(self, other: Rhs) -> Self::Output;
}

/// Trait for subtraction (`-`) in logic code.
#[diagnostic::on_unimplemented(
    message = "Cannot subtract `{Rhs}` from `{Self}` in logic",
    label = "no implementation for `{Self} - {Rhs}` in logic"
)]
pub trait SubLogic<Rhs = Self> {
    type Output;

    #[logic]
    fn sub(self, other: Rhs) -> Self::Output;
}

/// Trait for multiplication (`*`) in logic code.
#[diagnostic::on_unimplemented(
    message = "Cannot multiply `{Self}` by `{Rhs}` in logic",
    label = "no implementation for `{Self} * {Rhs}` in logic"
)]
pub trait MulLogic<Rhs = Self> {
    type Output;

    #[logic]
    fn mul(self, other: Rhs) -> Self::Output;
}

/// Trait for division (`/`) in logic code.
#[diagnostic::on_unimplemented(
    message = "Cannot divide `{Self}` by `{Rhs}` in logic",
    label = "no implementation for `{Self} / {Rhs}` in logic"
)]
pub trait DivLogic<Rhs = Self> {
    type Output;

    #[logic]
    fn div(self, other: Rhs) -> Self::Output;
}

/// Trait for remainder (`%`) in logic code.
#[diagnostic::on_unimplemented(
    message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}` in logic",
    label = "no implementation for `{Self} % {Rhs}` in logic"
)]
pub trait RemLogic<Rhs = Self> {
    type Output;

    #[logic]
    fn rem(self, other: Rhs) -> Self::Output;
}

/// Trait for negation (unary `-`) in logic code.
#[diagnostic::on_unimplemented(
    message = "cannot apply unary operator `-` to type `{Self}`",
    label = "cannot apply unary operator `-` in logic"
)]
pub trait NegLogic {
    type Output;

    #[logic]
    fn neg(self) -> Self::Output;
}