Skip to content

bool: make the from_str function a FromStr impl #5256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//! Boolean logic

use option::{None, Option, Some};
use from_str::FromStr;

#[cfg(notest)] use cmp;

/// Negation / inverse
Expand Down Expand Up @@ -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<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
}
}
}

Expand All @@ -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))
}
}

Expand Down
1 change: 0 additions & 1 deletion src/libcore/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ use option::Option;
pub trait FromStr {
static pure fn from_str(s: &str) -> Option<Self>;
}