File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 1212//! Boolean logic
1313
1414use option:: { None , Option , Some } ;
15+ use from_str:: FromStr ;
16+
1517#[ cfg( notest) ] use cmp;
1618
1719/// Negation / inverse
@@ -46,13 +48,15 @@ pub pure fn is_true(v: bool) -> bool { v }
4648pub pure fn is_false ( v : bool ) -> bool { !v }
4749
4850/// Parse logic value from `s`
49- pub pure fn from_str ( s : & str ) -> Option < bool > {
50- if s == "true" {
51- Some ( true )
52- } else if s == "false" {
53- Some ( false )
54- } else {
55- None
51+ impl FromStr for bool {
52+ static pure fn from_str( s: & str ) -> Option < bool > {
53+ if s == "true" {
54+ Some ( true )
55+ } else if s == "false" {
56+ Some ( false )
57+ } else {
58+ None
59+ }
5660 }
5761}
5862
@@ -79,8 +83,10 @@ impl cmp::Eq for bool {
7983
8084#[ test]
8185pub fn test_bool_from_str ( ) {
86+ use from_str:: FromStr ;
87+
8288 do all_values |v| {
83- assert Some ( v) == from_str ( to_str ( v) )
89+ assert Some ( v) == FromStr :: from_str ( to_str ( v) )
8490 }
8591}
8692
Original file line number Diff line number Diff line change @@ -15,4 +15,3 @@ use option::Option;
1515pub trait FromStr {
1616 static pure fn from_str( s: & str ) -> Option < Self > ;
1717}
18-
You can’t perform that action at this time.
0 commit comments