Skip to content

bool: rm functions duplicating methods #6864

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
83 changes: 38 additions & 45 deletions src/libstd/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
use cmp::{Eq, Ord, TotalOrd, Ordering};
use option::{None, Option, Some};
use from_str::FromStr;
use to_str::ToStr;

/**
* Negation of a boolean value.
Expand Down Expand Up @@ -129,44 +130,6 @@ pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
*/
pub fn implies(a: bool, b: bool) -> bool { !a || b }

/**
* Equality between two boolean values.
*
* Two booleans are equal if they have the same value.
*
* # Examples
*
* ~~~ {.rust}
* rusti> std::bool::eq(false, true)
* false
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::eq(false, false)
* true
* ~~~
*/
pub fn eq(a: bool, b: bool) -> bool { a == b }

/**
* Non-equality between two boolean values.
*
* Two booleans are not equal if they have different values.
*
* # Examples
*
* ~~~ {.rust}
* rusti> std::bool::ne(false, true)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::ne(false, false)
* false
* ~~~
*/
pub fn ne(a: bool, b: bool) -> bool { a != b }

/**
* Is a given boolean value true?
*
Expand Down Expand Up @@ -239,16 +202,21 @@ impl FromStr for bool {
* # Examples
*
* ~~~ {.rust}
* rusti> std::bool::to_str(true)
* rusti> true.to_str()
* "true"
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_str(false)
* rusti> false.to_str()
* "false"
* ~~~
*/
pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
impl ToStr for bool {
#[inline(always)]
fn to_str(&self) -> ~str {
if *self { ~"true" } else { ~"false" }
}
}

/**
* Iterates over all truth values, passing them to the given block.
Expand All @@ -258,7 +226,7 @@ pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
* # Examples
* ~~~
* do std::bool::all_values |x: bool| {
* println(std::bool::to_str(x));
* println(x.to_str())
* }
* ~~~
*/
Expand Down Expand Up @@ -303,6 +271,31 @@ impl TotalOrd for bool {
fn cmp(&self, other: &bool) -> Ordering { to_bit(*self).cmp(&to_bit(*other)) }
}

/**
* Equality between two boolean values.
*
* Two booleans are equal if they have the same value.
*
* ~~~ {.rust}
* rusti> false.eq(&true)
* false
* ~~~
*
* ~~~ {.rust}
* rusti> false == false
* true
* ~~~
*
* ~~~ {.rust}
* rusti> false != true
* true
* ~~~
*
* ~~~ {.rust}
* rusti> false.ne(&false)
* false
* ~~~
*/
#[cfg(not(test))]
impl Eq for bool {
#[inline(always)]
Expand All @@ -319,14 +312,14 @@ mod tests {
#[test]
fn test_bool_from_str() {
do all_values |v| {
assert!(Some(v) == FromStr::from_str(to_str(v)))
assert!(Some(v) == FromStr::from_str(v.to_str()))
}
}

#[test]
fn test_bool_to_str() {
assert_eq!(to_str(false), ~"false");
assert_eq!(to_str(true), ~"true");
assert_eq!(false.to_str(), ~"false");
assert_eq!(true.to_str(), ~"true");
}

#[test]
Expand Down
4 changes: 0 additions & 4 deletions src/libstd/to_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ pub trait ToStrConsume {
fn to_str_consume(self) -> ~str;
}

impl ToStr for bool {
#[inline(always)]
fn to_str(&self) -> ~str { ::bool::to_str(*self) }
}
impl ToStr for () {
#[inline(always)]
fn to_str(&self) -> ~str { ~"()" }
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/reflect-visit-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl TyVisitor for my_visitor {
fn visit_nil(&self) -> bool { true }
fn visit_bool(&self) -> bool {
do self.get::<bool>() |b| {
self.vals.push(bool::to_str(b));
self.vals.push(b.to_str());
};
true
}
Expand Down