Skip to content

Commit 7782aa8

Browse files
committed
bool: make the from_str function a FromStr impl
1 parent 67100dd commit 7782aa8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/libcore/bool.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//! Boolean logic
1313
1414
use 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 }
4648
pub 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]
8185
pub 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

src/libcore/from_str.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ use option::Option;
1515
pub trait FromStr {
1616
static pure fn from_str(s: &str) -> Option<Self>;
1717
}
18-

0 commit comments

Comments
 (0)