8
8
9
9
use cmp:: Eq ;
10
10
11
- export not, and, or, xor, implies;
12
- export eq, ne, is_true, is_false;
13
- export from_str, to_str, all_values, to_bit;
14
-
15
11
/// Negation / inverse
16
- pure fn not ( v : bool ) -> bool { !v }
12
+ pub pure fn not ( v : bool ) -> bool { !v }
17
13
18
14
/// Conjunction
19
- pure fn and ( a : bool , b : bool ) -> bool { a && b }
15
+ pub pure fn and ( a : bool , b : bool ) -> bool { a && b }
20
16
21
17
/// Disjunction
22
- pure fn or ( a : bool , b : bool ) -> bool { a || b }
18
+ pub pure fn or ( a : bool , b : bool ) -> bool { a || b }
23
19
24
20
/**
25
21
* Exclusive or
26
22
*
27
23
* Identical to `or(and(a, not(b)), and(not(a), b))`
28
24
*/
29
- pure fn xor ( a : bool , b : bool ) -> bool { ( a && !b) || ( !a && b) }
25
+ pub pure fn xor ( a : bool , b : bool ) -> bool { ( a && !b) || ( !a && b) }
30
26
31
27
/// Implication in the logic, i.e. from `a` follows `b`
32
- pure fn implies ( a : bool , b : bool ) -> bool { !a || b }
28
+ pub pure fn implies ( a : bool , b : bool ) -> bool { !a || b }
33
29
34
30
/// true if truth values `a` and `b` are indistinguishable in the logic
35
- pure fn eq ( a : bool , b : bool ) -> bool { a == b }
31
+ pub pure fn eq ( a : bool , b : bool ) -> bool { a == b }
36
32
37
33
/// true if truth values `a` and `b` are distinguishable in the logic
38
- pure fn ne ( a : bool , b : bool ) -> bool { a != b }
34
+ pub pure fn ne ( a : bool , b : bool ) -> bool { a != b }
39
35
40
36
/// true if `v` represents truth in the logic
41
- pure fn is_true ( v : bool ) -> bool { v }
37
+ pub pure fn is_true ( v : bool ) -> bool { v }
42
38
43
39
/// true if `v` represents falsehood in the logic
44
- pure fn is_false ( v : bool ) -> bool { !v }
40
+ pub pure fn is_false ( v : bool ) -> bool { !v }
45
41
46
42
/// Parse logic value from `s`
47
- pure fn from_str ( s : & str ) -> Option < bool > {
43
+ pub pure fn from_str ( s : & str ) -> Option < bool > {
48
44
if s == "true" {
49
45
Some ( true )
50
46
} else if s == "false" {
@@ -55,40 +51,40 @@ pure fn from_str(s: &str) -> Option<bool> {
55
51
}
56
52
57
53
/// Convert `v` into a string
58
- pure fn to_str ( v : bool ) -> ~str { if v { ~"true " } else { ~"false " } }
54
+ pub pure fn to_str ( v : bool ) -> ~str { if v { ~"true " } else { ~"false " } }
59
55
60
56
/**
61
57
* Iterates over all truth values by passing them to `blk` in an unspecified
62
58
* order
63
59
*/
64
- fn all_values ( blk : fn ( v : bool ) ) {
60
+ pub fn all_values ( blk : fn ( v : bool ) ) {
65
61
blk ( true ) ;
66
62
blk ( false ) ;
67
63
}
68
64
69
65
/// converts truth value to an 8 bit byte
70
- pure fn to_bit ( v : bool ) -> u8 { if v { 1u8 } else { 0u8 } }
66
+ pub pure fn to_bit ( v : bool ) -> u8 { if v { 1u8 } else { 0u8 } }
71
67
72
68
impl bool : cmp:: Eq {
73
69
pure fn eq ( other : & bool ) -> bool { self == ( * other) }
74
70
pure fn ne ( other : & bool ) -> bool { self != ( * other) }
75
71
}
76
72
77
73
#[ test]
78
- fn test_bool_from_str ( ) {
74
+ pub fn test_bool_from_str ( ) {
79
75
do all_values |v| {
80
76
assert Some ( v) == from_str ( bool:: to_str ( v) )
81
77
}
82
78
}
83
79
84
80
#[ test]
85
- fn test_bool_to_str ( ) {
81
+ pub fn test_bool_to_str ( ) {
86
82
assert to_str ( false ) == ~"false ";
87
83
assert to_str ( true ) == ~"true ";
88
84
}
89
85
90
86
#[ test]
91
- fn test_bool_to_bit ( ) {
87
+ pub fn test_bool_to_bit ( ) {
92
88
do all_values |v| {
93
89
assert to_bit ( v) == if is_true ( v) { 1u8 } else { 0u8 } ;
94
90
}
0 commit comments