From 7782aa82d2238371f8d62ed8122d05c2cc225317 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Mar 2013 13:05:59 -0500 Subject: [PATCH] bool: make the from_str function a FromStr impl --- src/libcore/bool.rs | 22 ++++++++++++++-------- src/libcore/from_str.rs | 1 - 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 26a68e3a1990c..b4300d9848335 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -12,6 +12,8 @@ //! Boolean logic use option::{None, Option, Some}; +use from_str::FromStr; + #[cfg(notest)] use cmp; /// Negation / inverse @@ -46,13 +48,15 @@ pub pure fn is_true(v: bool) -> bool { v } pub pure fn is_false(v: bool) -> bool { !v } /// Parse logic value from `s` -pub pure fn from_str(s: &str) -> Option { - 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 { + 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)) } } diff --git a/src/libcore/from_str.rs b/src/libcore/from_str.rs index 9322c7e7cb822..166ba2252a9d4 100644 --- a/src/libcore/from_str.rs +++ b/src/libcore/from_str.rs @@ -15,4 +15,3 @@ use option::Option; pub trait FromStr { static pure fn from_str(s: &str) -> Option; } -