auto merge of #5256 : thestinger/rust/bool, r=brson
This commit is contained in:
commit
c3c018f8ab
2 changed files with 14 additions and 9 deletions
|
|
@ -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<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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,4 +15,3 @@ use option::Option;
|
|||
pub trait FromStr {
|
||||
static pure fn from_str(s: &str) -> Option<Self>;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue