10
10
11
11
//! Operations on boolean values (`bool` type)
12
12
//!
13
- //! A quick summary:
14
- //!
15
- //! Implementations of the following traits:
16
- //!
17
- //! * `Not`
18
- //! * `BitAnd`
19
- //! * `BitOr`
20
- //! * `BitXor`
21
- //! * `Ord`
22
- //! * `TotalOrd`
23
- //! * `Eq`
24
- //! * `TotalEq`
25
- //! * `Default`
26
- //!
27
13
//! A `to_bit` conversion function.
28
14
29
15
use num:: { Int , one, zero} ;
30
16
31
- #[ cfg( not( test) ) ] use cmp:: { Eq , Ord , TotalOrd , Ordering , TotalEq } ;
32
- #[ cfg( not( test) ) ] use ops:: { Not , BitAnd , BitOr , BitXor } ;
33
- #[ cfg( not( test) ) ] use default:: Default ;
34
-
35
17
/////////////////////////////////////////////////////////////////////////////
36
18
// Freestanding functions
37
19
/////////////////////////////////////////////////////////////////////////////
@@ -51,131 +33,6 @@ pub fn to_bit<N: Int>(p: bool) -> N {
51
33
if p { one ( ) } else { zero ( ) }
52
34
}
53
35
54
- /////////////////////////////////////////////////////////////////////////////
55
- // Trait impls on `bool`
56
- /////////////////////////////////////////////////////////////////////////////
57
-
58
- #[ cfg( not( test) ) ]
59
- impl Not < bool > for bool {
60
- /// The logical complement of a boolean value.
61
- ///
62
- /// # Examples
63
- ///
64
- /// ```rust
65
- /// assert_eq!(!true, false);
66
- /// assert_eq!(!false, true);
67
- /// ```
68
- #[ inline]
69
- fn not ( & self ) -> bool { !* self }
70
- }
71
-
72
- #[ cfg( not( test) ) ]
73
- impl BitAnd < bool , bool > for bool {
74
- /// Conjunction of two boolean values.
75
- ///
76
- /// # Examples
77
- ///
78
- /// ```rust
79
- /// assert_eq!(false.bitand(&false), false);
80
- /// assert_eq!(true.bitand(&false), false);
81
- /// assert_eq!(false.bitand(&true), false);
82
- /// assert_eq!(true.bitand(&true), true);
83
- ///
84
- /// assert_eq!(false & false, false);
85
- /// assert_eq!(true & false, false);
86
- /// assert_eq!(false & true, false);
87
- /// assert_eq!(true & true, true);
88
- /// ```
89
- #[ inline]
90
- fn bitand ( & self , b : & bool ) -> bool { * self & * b }
91
- }
92
-
93
- #[ cfg( not( test) ) ]
94
- impl BitOr < bool , bool > for bool {
95
- /// Disjunction of two boolean values.
96
- ///
97
- /// # Examples
98
- ///
99
- /// ```rust
100
- /// assert_eq!(false.bitor(&false), false);
101
- /// assert_eq!(true.bitor(&false), true);
102
- /// assert_eq!(false.bitor(&true), true);
103
- /// assert_eq!(true.bitor(&true), true);
104
- ///
105
- /// assert_eq!(false | false, false);
106
- /// assert_eq!(true | false, true);
107
- /// assert_eq!(false | true, true);
108
- /// assert_eq!(true | true, true);
109
- /// ```
110
- #[ inline]
111
- fn bitor ( & self , b : & bool ) -> bool { * self | * b }
112
- }
113
-
114
- #[ cfg( not( test) ) ]
115
- impl BitXor < bool , bool > for bool {
116
- /// An 'exclusive or' of two boolean values.
117
- ///
118
- /// 'exclusive or' is identical to `or(and(a, not(b)), and(not(a), b))`.
119
- ///
120
- /// # Examples
121
- ///
122
- /// ```rust
123
- /// assert_eq!(false.bitxor(&false), false);
124
- /// assert_eq!(true.bitxor(&false), true);
125
- /// assert_eq!(false.bitxor(&true), true);
126
- /// assert_eq!(true.bitxor(&true), false);
127
- ///
128
- /// assert_eq!(false ^ false, false);
129
- /// assert_eq!(true ^ false, true);
130
- /// assert_eq!(false ^ true, true);
131
- /// assert_eq!(true ^ true, false);
132
- /// ```
133
- #[ inline]
134
- fn bitxor ( & self , b : & bool ) -> bool { * self ^ * b }
135
- }
136
-
137
- #[ cfg( not( test) ) ]
138
- impl Ord for bool {
139
- #[ inline]
140
- fn lt ( & self , other : & bool ) -> bool {
141
- to_bit :: < u8 > ( * self ) < to_bit ( * other)
142
- }
143
- }
144
-
145
- #[ cfg( not( test) ) ]
146
- impl TotalOrd for bool {
147
- #[ inline]
148
- fn cmp ( & self , other : & bool ) -> Ordering {
149
- to_bit :: < u8 > ( * self ) . cmp ( & to_bit ( * other) )
150
- }
151
- }
152
-
153
- /// Equality between two boolean values.
154
- ///
155
- /// Two booleans are equal if they have the same value.
156
- ///
157
- /// # Examples
158
- ///
159
- /// ```rust
160
- /// assert_eq!(false.eq(&true), false);
161
- /// assert_eq!(false == false, true);
162
- /// assert_eq!(false != true, true);
163
- /// assert_eq!(false.ne(&false), false);
164
- /// ```
165
- #[ cfg( not( test) ) ]
166
- impl Eq for bool {
167
- #[ inline]
168
- fn eq ( & self , other : & bool ) -> bool { ( * self ) == ( * other) }
169
- }
170
-
171
- #[ cfg( not( test) ) ]
172
- impl TotalEq for bool { }
173
-
174
- #[ cfg( not( test) ) ]
175
- impl Default for bool {
176
- fn default ( ) -> bool { false }
177
- }
178
-
179
36
#[ cfg( test) ]
180
37
mod tests {
181
38
use realstd:: prelude:: * ;
0 commit comments