File tree 2 files changed +14
-9
lines changed
2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 12
12
//! Boolean logic
13
13
14
14
use option:: { None , Option , Some } ;
15
+ use from_str:: FromStr ;
16
+
15
17
#[ cfg( notest) ] use cmp;
16
18
17
19
/// Negation / inverse
@@ -46,13 +48,15 @@ pub pure fn is_true(v: bool) -> bool { v }
46
48
pub pure fn is_false ( v : bool ) -> bool { !v }
47
49
48
50
/// 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
+ }
56
60
}
57
61
}
58
62
@@ -79,8 +83,10 @@ impl cmp::Eq for bool {
79
83
80
84
#[ test]
81
85
pub fn test_bool_from_str ( ) {
86
+ use from_str:: FromStr ;
87
+
82
88
do all_values |v| {
83
- assert Some ( v) == from_str ( to_str ( v) )
89
+ assert Some ( v) == FromStr :: from_str ( to_str ( v) )
84
90
}
85
91
}
86
92
Original file line number Diff line number Diff line change @@ -15,4 +15,3 @@ use option::Option;
15
15
pub trait FromStr {
16
16
static pure fn from_str( s: & str ) -> Option < Self > ;
17
17
}
18
-
You can’t perform that action at this time.
0 commit comments