@@ -38,6 +38,7 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
38
38
use cmp:: { Eq , Ord , TotalOrd , Ordering } ;
39
39
use option:: { None , Option , Some } ;
40
40
use from_str:: FromStr ;
41
+ use to_str:: ToStr ;
41
42
42
43
/**
43
44
* Negation of a boolean value.
@@ -129,44 +130,6 @@ pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
129
130
*/
130
131
pub fn implies ( a : bool , b : bool ) -> bool { !a || b }
131
132
132
- /**
133
- * Equality between two boolean values.
134
- *
135
- * Two booleans are equal if they have the same value.
136
- *
137
- * # Examples
138
- *
139
- * ~~~ {.rust}
140
- * rusti> std::bool::eq(false, true)
141
- * false
142
- * ~~~
143
- *
144
- * ~~~ {.rust}
145
- * rusti> std::bool::eq(false, false)
146
- * true
147
- * ~~~
148
- */
149
- pub fn eq ( a : bool , b : bool ) -> bool { a == b }
150
-
151
- /**
152
- * Non-equality between two boolean values.
153
- *
154
- * Two booleans are not equal if they have different values.
155
- *
156
- * # Examples
157
- *
158
- * ~~~ {.rust}
159
- * rusti> std::bool::ne(false, true)
160
- * true
161
- * ~~~
162
- *
163
- * ~~~ {.rust}
164
- * rusti> std::bool::ne(false, false)
165
- * false
166
- * ~~~
167
- */
168
- pub fn ne ( a : bool , b : bool ) -> bool { a != b }
169
-
170
133
/**
171
134
* Is a given boolean value true?
172
135
*
@@ -239,16 +202,21 @@ impl FromStr for bool {
239
202
* # Examples
240
203
*
241
204
* ~~~ {.rust}
242
- * rusti> std::bool:: to_str(true )
205
+ * rusti> true. to_str()
243
206
* "true"
244
207
* ~~~
245
208
*
246
209
* ~~~ {.rust}
247
- * rusti> std::bool:: to_str(false )
210
+ * rusti> false. to_str()
248
211
* "false"
249
212
* ~~~
250
213
*/
251
- pub fn to_str ( v : bool ) -> ~str { if v { ~"true " } else { ~"false " } }
214
+ impl ToStr for bool {
215
+ #[ inline( always) ]
216
+ fn to_str ( & self ) -> ~str {
217
+ if * self { ~"true " } else { ~"false " }
218
+ }
219
+ }
252
220
253
221
/**
254
222
* Iterates over all truth values, passing them to the given block.
@@ -258,7 +226,7 @@ pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
258
226
* # Examples
259
227
* ~~~
260
228
* do std::bool::all_values |x: bool| {
261
- * println(std::bool:: to_str(x));
229
+ * println(x. to_str())
262
230
* }
263
231
* ~~~
264
232
*/
@@ -303,6 +271,31 @@ impl TotalOrd for bool {
303
271
fn cmp ( & self , other : & bool ) -> Ordering { to_bit ( * self ) . cmp ( & to_bit ( * other) ) }
304
272
}
305
273
274
+ /**
275
+ * Equality between two boolean values.
276
+ *
277
+ * Two booleans are equal if they have the same value.
278
+ *
279
+ * ~~~ {.rust}
280
+ * rusti> false.eq(&true)
281
+ * false
282
+ * ~~~
283
+ *
284
+ * ~~~ {.rust}
285
+ * rusti> false == false
286
+ * true
287
+ * ~~~
288
+ *
289
+ * ~~~ {.rust}
290
+ * rusti> false != true
291
+ * true
292
+ * ~~~
293
+ *
294
+ * ~~~ {.rust}
295
+ * rusti> false.ne(&false)
296
+ * false
297
+ * ~~~
298
+ */
306
299
#[ cfg( not( test) ) ]
307
300
impl Eq for bool {
308
301
#[ inline( always) ]
@@ -319,14 +312,14 @@ mod tests {
319
312
#[ test]
320
313
fn test_bool_from_str ( ) {
321
314
do all_values |v| {
322
- assert ! ( Some ( v) == FromStr :: from_str( to_str( v ) ) )
315
+ assert ! ( Some ( v) == FromStr :: from_str( v . to_str( ) ) )
323
316
}
324
317
}
325
318
326
319
#[ test]
327
320
fn test_bool_to_str ( ) {
328
- assert_eq ! ( to_str( false ) , ~"false ");
329
- assert_eq!(to_str(true ), ~" true " ) ;
321
+ assert_eq ! ( false . to_str( ) , ~"false ");
322
+ assert_eq!(true. to_str(), ~" true " ) ;
330
323
}
331
324
332
325
#[ test]
0 commit comments