-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvalues_booleans.rs
89 lines (55 loc) · 1.34 KB
/
values_booleans.rs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
use super::prelude::*;
pub mod exports {
pub use super::Boolean;
pub use super::boolean;
}
#[ derive ( Clone ) ] // OK
#[ cfg_attr ( feature = "vonuvoli_eqord", derive ( Eq, PartialEq, Ord, PartialOrd ) ) ] // OK
#[ cfg_attr ( feature = "vonuvoli_fmt_debug", derive ( Debug ) ) ] // OK
pub struct Boolean ( pub bool );
impl Boolean {
pub fn value (&self) -> (bool) {
self.0
}
pub fn is_true (&self) -> (bool) {
self.0
}
pub fn is_false (&self) -> (bool) {
! self.0
}
pub fn is_self (&self, other : &Boolean) -> (bool) {
bool::eq (&self.0, &other.0)
}
}
impl Boolean {
pub fn not (&self) -> (Boolean) {
(!self.0) .into ()
}
pub fn and (&self, other : &Boolean) -> (Boolean) {
(self.0 && other.0) .into ()
}
pub fn or (&self, other : &Boolean) -> (Boolean) {
(self.0 || other.0) .into ()
}
pub fn xor (&self, other : &Boolean) -> (Boolean) {
(self.0 ^ other.0) .into ()
}
pub fn nand (&self, other : &Boolean) -> (Boolean) {
self.and (other) .not ()
}
pub fn nor (&self, other : &Boolean) -> (Boolean) {
self.or (other) .not ()
}
pub fn nxor (&self, other : &Boolean) -> (Boolean) {
self.xor (other) .not ()
}
}
impl ops::Not for Boolean {
type Output = Boolean;
fn not (self) -> (Boolean) {
Boolean::not (&self)
}
}
pub fn boolean (value : bool) -> (Boolean) {
Boolean (value)
}