megabool_rs/
lib.rs

1//! # Megabool, the bestest boolean ever made.
2//!
3//! Since old boolean has two possible variants only, the Megabool has much more, for absolutely any purpose!
4//!
5//! *Note: this is a joke, don't use this shit.*
6
7use std::ops::{Add, Div, Mul, Sub};
8use rand::prelude::*;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
11#[repr(u8)] // It's enough.
12/// Megabool!
13pub enum Megabool {
14    /// It's `true`.
15    True,
16
17    /// It's `false`.
18    False,
19
20    /// It's `not yes`.
21    Yesnt,
22
23    /// Not `true` and not `false`.
24    Neither,
25
26    /// `True` and `false` at the same time.
27    Both,
28
29    /// Maybe `true`, maybe `false`. Try it yourself.
30    Maybe,
31
32    /// It's funking obliviously true.
33    ObliviouslyTrue,
34
35    /// Literally false.
36    ObliviouslyFalse,
37
38    /// Depends on some circumstances, result may be various.
39    ItDepends,
40
41    /// Oscillating result.
42    Oscillating,
43
44    /// Too complicated to calculate the result, just leave this variant.
45    ItsComplicated,
46
47    /// `True` + `true`
48    DoubleTrue,
49}
50impl Megabool {
51    /// Let your mechine choose, will it be `true` or `false`.
52    pub fn let_me_choose() -> Self {
53        let n: u8 = rand::thread_rng().gen_range(0..=2);
54        match n {
55            0 => Self::False,
56            1 => Self::True,
57            2 => Self::Both,
58
59            _ => Self::Neither,
60        }
61    }
62}
63impl From<bool> for Megabool {
64    fn from(value: bool) -> Self {
65        match value {
66            true => Self::True,
67            false => Self::False,
68        }
69    }
70}
71impl Add for Megabool {
72    type Output = Self;
73
74    fn add(self, rhs: Self) -> Self::Output {
75        match (self, rhs) {
76            (Self::True, Self::True) => Self::DoubleTrue,
77            _ => Self::Neither,
78        }
79    }
80}
81impl Sub for Megabool {
82    type Output = Self;
83
84    fn sub(self, rhs: Self) -> Self::Output {
85        match (self, rhs) {
86            (Self::DoubleTrue, Self::True) => Self::True,
87            _ => Self::Neither,
88        }
89    }
90}
91impl Mul for Megabool {
92    type Output = Self;
93
94    fn mul(self, rhs: Self) -> Self::Output {
95        match (self, rhs) {
96            (Self::True, Self::True) => Self::ObliviouslyTrue,
97            (Self::False, Self::False) => Self::ObliviouslyFalse,
98            _ => Self::Neither,
99        }
100    }
101}
102impl Div for Megabool {
103    type Output = Self;
104
105    fn div(self, rhs: Self) -> Self::Output {
106        match (self, rhs) {
107            (Self::ObliviouslyTrue, Self::True) => Self::True,
108            (Self::ObliviouslyFalse, Self::False) => Self::False,
109            _ => Self::Neither,
110        }
111    }
112}