The bool module contains useful code to help work with boolean values.

A quick summary:

Trait implementations for bool

Implementations of the following traits:

Various functions to compare bools

All of the standard comparison functions one would expect: and, eq, or, and more.

Also, a few conversion functions: to_bit and to_str.

Finally, some inquries into the nature of truth: is_true and is_false.

Implementation of FromStr for bool

Parse a bool from a str.

Yields an Option<bool>, because str may or may not actually be parseable.

Examples

rusti> FromStr::from_str::<bool>("true")
Some(true)
rusti> FromStr::from_str::<bool>("false")
Some(false)
rusti> FromStr::from_str::<bool>("not even a boolean")
None

Method from_str

fn from_str(s: &str) -> Option<bool>

Implementation of ToStr for bool

Convert a bool to a str.

Examples

rusti> true.to_str()
"true"
rusti> false.to_str()
"false"

Method to_str

fn to_str(&self) -> ~str

Implementation of Ord for bool

Method lt

fn lt(&self, other: &bool) -> bool

Method le

fn le(&self, other: &bool) -> bool

Method gt

fn gt(&self, other: &bool) -> bool

Method ge

fn ge(&self, other: &bool) -> bool

Implementation of TotalOrd for bool

Method cmp

fn cmp(&self, other: &bool) -> Ordering

Implementation of Eq for bool

Equality between two boolean values.

Two booleans are equal if they have the same value.

rusti> false.eq(&true)
false
rusti> false == false
true
rusti> false != true
true
rusti> false.ne(&false)
false

Method eq

fn eq(&self, other: &bool) -> bool

Method ne

fn ne(&self, other: &bool) -> bool

Function all_values

fn all_values(blk: &fn(v: bool))

Iterates over all truth values, passing them to the given block.

There are no guarantees about the order values will be given.

Examples

do std::bool::all_values |x: bool| {
    println(x.to_str())
}

Function and

fn and(a: bool, b: bool) -> bool

Conjunction of two boolean values.

Examples

rusti> std::bool::and(true, false)
false
rusti> std::bool::and(true, true)
true

Function implies

fn implies(a: bool, b: bool) -> bool

Implication between two boolean values.

Implication is often phrased as 'if a then b.'

'if a then b' is equivalent to !a || b.

Examples

~ {.rust} rusti> std::bool::implies(true, true) true

rusti> std::bool::implies(true, false)
false

Function is_false

fn is_false(v: bool) -> bool

Is a given boolean value false?

Examples

rusti> std::bool::is_false(false)
true
rusti> std::bool::is_false(true)
false

Function is_true

fn is_true(v: bool) -> bool

Is a given boolean value true?

Examples

rusti> std::bool::is_true(true)
true
rusti> std::bool::is_true(false)
false

Function not

fn not(v: bool) -> bool

Negation of a boolean value.

Examples

rusti> std::bool::not(true)
false
rusti> std::bool::not(false)
true

Function or

fn or(a: bool, b: bool) -> bool

Disjunction of two boolean values.

Examples

rusti> std::bool::or(true, false)
true
rusti> std::bool::or(false, false)
false

Function to_bit

fn to_bit(v: bool) -> u8

Convert a bool to a u8.

Examples

rusti> std::bool::to_bit(true)
1
rusti> std::bool::to_bit(false)
0

Function xor

fn xor(a: bool, b: bool) -> bool

An 'exclusive or' of two boolean values.

'exclusive or' is identical to or(and(a, not(b)), and(not(a), b)).

Examples

rusti> std::bool::xor(true, false)
true
rusti> std::bool::xor(true, true)
false