libcore: De-export bool

This commit is contained in:
Patrick Walton 2012-09-26 14:54:26 -07:00
parent 8b13912a83
commit e956edeb55
1 changed files with 16 additions and 20 deletions

View File

@ -8,43 +8,39 @@
use cmp::Eq;
export not, and, or, xor, implies;
export eq, ne, is_true, is_false;
export from_str, to_str, all_values, to_bit;
/// Negation / inverse
pure fn not(v: bool) -> bool { !v }
pub pure fn not(v: bool) -> bool { !v }
/// Conjunction
pure fn and(a: bool, b: bool) -> bool { a && b }
pub pure fn and(a: bool, b: bool) -> bool { a && b }
/// Disjunction
pure fn or(a: bool, b: bool) -> bool { a || b }
pub pure fn or(a: bool, b: bool) -> bool { a || b }
/**
* Exclusive or
*
* Identical to `or(and(a, not(b)), and(not(a), b))`
*/
pure fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
pub pure fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
/// Implication in the logic, i.e. from `a` follows `b`
pure fn implies(a: bool, b: bool) -> bool { !a || b }
pub pure fn implies(a: bool, b: bool) -> bool { !a || b }
/// true if truth values `a` and `b` are indistinguishable in the logic
pure fn eq(a: bool, b: bool) -> bool { a == b }
pub pure fn eq(a: bool, b: bool) -> bool { a == b }
/// true if truth values `a` and `b` are distinguishable in the logic
pure fn ne(a: bool, b: bool) -> bool { a != b }
pub pure fn ne(a: bool, b: bool) -> bool { a != b }
/// true if `v` represents truth in the logic
pure fn is_true(v: bool) -> bool { v }
pub pure fn is_true(v: bool) -> bool { v }
/// true if `v` represents falsehood in the logic
pure fn is_false(v: bool) -> bool { !v }
pub pure fn is_false(v: bool) -> bool { !v }
/// Parse logic value from `s`
pure fn from_str(s: &str) -> Option<bool> {
pub pure fn from_str(s: &str) -> Option<bool> {
if s == "true" {
Some(true)
} else if s == "false" {
@ -55,19 +51,19 @@ pure fn from_str(s: &str) -> Option<bool> {
}
/// Convert `v` into a string
pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
pub pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
/**
* Iterates over all truth values by passing them to `blk` in an unspecified
* order
*/
fn all_values(blk: fn(v: bool)) {
pub fn all_values(blk: fn(v: bool)) {
blk(true);
blk(false);
}
/// converts truth value to an 8 bit byte
pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
pub pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
impl bool : cmp::Eq {
pure fn eq(other: &bool) -> bool { self == (*other) }
@ -75,20 +71,20 @@ impl bool : cmp::Eq {
}
#[test]
fn test_bool_from_str() {
pub fn test_bool_from_str() {
do all_values |v| {
assert Some(v) == from_str(bool::to_str(v))
}
}
#[test]
fn test_bool_to_str() {
pub fn test_bool_to_str() {
assert to_str(false) == ~"false";
assert to_str(true) == ~"true";
}
#[test]
fn test_bool_to_bit() {
pub fn test_bool_to_bit() {
do all_values |v| {
assert to_bit(v) == if is_true(v) { 1u8 } else { 0u8 };
}