@@ -38,6 +38,7 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
3838use cmp:: { Eq , Ord , TotalOrd , Ordering } ;
3939use option:: { None , Option , Some } ;
4040use from_str:: FromStr ;
41+ use to_str:: ToStr ;
4142
4243/**
4344* Negation of a boolean value.
@@ -129,44 +130,6 @@ pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
129130*/
130131pub fn implies ( a : bool , b : bool ) -> bool { !a || b }
131132
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-
170133/**
171134* Is a given boolean value true?
172135*
@@ -239,16 +202,21 @@ impl FromStr for bool {
239202* # Examples
240203*
241204* ~~~ {.rust}
242- * rusti> std::bool:: to_str(true )
205+ * rusti> true. to_str()
243206* "true"
244207* ~~~
245208*
246209* ~~~ {.rust}
247- * rusti> std::bool:: to_str(false )
210+ * rusti> false. to_str()
248211* "false"
249212* ~~~
250213*/
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+ }
252220
253221/**
254222* 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" } }
258226* # Examples
259227* ~~~
260228* do std::bool::all_values |x: bool| {
261- * println(std::bool:: to_str(x));
229+ * println(x. to_str())
262230* }
263231* ~~~
264232*/
@@ -303,6 +271,31 @@ impl TotalOrd for bool {
303271 fn cmp ( & self , other : & bool ) -> Ordering { to_bit ( * self ) . cmp ( & to_bit ( * other) ) }
304272}
305273
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+ */
306299#[ cfg( not( test) ) ]
307300impl Eq for bool {
308301 #[ inline( always) ]
@@ -319,14 +312,14 @@ mod tests {
319312 #[ test]
320313 fn test_bool_from_str ( ) {
321314 do all_values |v| {
322- assert ! ( Some ( v) == FromStr :: from_str( to_str( v ) ) )
315+ assert ! ( Some ( v) == FromStr :: from_str( v . to_str( ) ) )
323316 }
324317 }
325318
326319 #[ test]
327320 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 " ) ;
330323 }
331324
332325 #[ test]
0 commit comments