Skip to main content

scratch_test_value/comparisons/
logic.rs

1use crate::{QuirkSink, SValue, quirks::SValueToBoolQ};
2
3impl SValue {
4    pub fn q_and<Q>(&self, other: &SValue, sink: &mut Q) -> bool
5    where
6        Q: QuirkSink<SValueToBoolQ>,
7    {
8        let a = self.q_as_bool(sink);
9        let b = other.q_as_bool(sink);
10        a && b
11    }
12    pub fn q_or<Q>(&self, other: &SValue, sink: &mut Q) -> bool
13    where
14        Q: QuirkSink<SValueToBoolQ>,
15    {
16        let a = self.q_as_bool(sink);
17        let b = other.q_as_bool(sink);
18        a || b
19    }
20    pub fn q_not<Q>(&self, sink: &mut Q) -> bool
21    where
22        Q: QuirkSink<SValueToBoolQ>,
23    {
24        !self.q_as_bool(sink)
25    }
26
27    #[allow(unused)]
28    pub(crate) fn and(&self, other: &SValue) -> bool {
29        // there should never be any errors for user programs as expression
30        // blocks (texts/numbers) can't be placed in condition wholes of shape <..>.
31        // Because of that errors can be ignored
32        self.q_and(other, &mut ())
33    }
34
35    #[allow(unused)]
36    pub(crate) fn or(&self, other: &SValue) -> bool {
37        // there should never be any errors for user programs as expression
38        // blocks (texts/numbers) can't be placed in condition wholes of shape <..>.
39        // Because of that errors can be ignored
40        self.q_or(other, &mut ())
41    }
42
43    #[allow(unused)]
44    pub(crate) fn not(&self) -> bool {
45        // there should never be any errors for user programs as expression
46        // blocks (texts/numbers) can't be placed in condition wholes of shape <..>.
47        // Because of that errors can be ignored
48        self.q_not(&mut ())
49    }
50}