]> git.lizzy.rs Git - rust.git/commitdiff
bool: make the from_str function a FromStr impl
authorDaniel Micay <danielmicay@gmail.com>
Wed, 6 Mar 2013 18:05:59 +0000 (13:05 -0500)
committerDaniel Micay <danielmicay@gmail.com>
Wed, 6 Mar 2013 18:05:59 +0000 (13:05 -0500)
src/libcore/bool.rs
src/libcore/from_str.rs

index 26a68e3a1990c2b313c9ae9cbdaf76221e4bf259..b4300d9848335546bd5d8f99f53311623defc7de 100644 (file)
@@ -12,6 +12,8 @@
 //! Boolean logic
 
 use option::{None, Option, Some};
+use from_str::FromStr;
+
 #[cfg(notest)] use cmp;
 
 /// Negation / inverse
 pub pure fn is_false(v: bool) -> bool { !v }
 
 /// Parse logic value from `s`
-pub pure fn from_str(s: &str) -> Option<bool> {
-    if s == "true" {
-        Some(true)
-    } else if s == "false" {
-        Some(false)
-    } else {
-        None
+impl FromStr for bool {
+    static pure fn from_str(s: &str) -> Option<bool> {
+        if s == "true" {
+            Some(true)
+        } else if s == "false" {
+            Some(false)
+        } else {
+            None
+        }
     }
 }
 
@@ -79,8 +83,10 @@ impl cmp::Eq for bool {
 
 #[test]
 pub fn test_bool_from_str() {
+    use from_str::FromStr;
+
     do all_values |v| {
-        assert Some(v) == from_str(to_str(v))
+        assert Some(v) == FromStr::from_str(to_str(v))
     }
 }
 
index 9322c7e7cb822baddfc323db9e4b830af4d63241..166ba2252a9d41c9e59e64197cee16b94753af38 100644 (file)
@@ -15,4 +15,3 @@
 pub trait FromStr {
     static pure fn from_str(s: &str) -> Option<Self>;
 }
-