1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! # The trit crate
//! A crate that provides a trinary type

//! ## Usage
//! ```
//! // Creates a type that is both true and false
//! let both = Trit::Both;
//! // both.is_true() == true
//! // both.is_false() == true
//! // both.only_true() == false
//! // both.only_false() == false
//! ```

#[cfg(test)]
mod tests {
	use Trit;

    #[test]
    fn can_be_both() {
    	assert!(Trit::Both.is_true());
    	assert!(Trit::Both.is_false());
    }

    #[test]
    fn can_be_only() {
    	assert!(Trit::True.only_true());
    	assert!(Trit::False.only_false());
    }
}

/// Used to denote a trinary value (True, False, or Both)
#[derive(PartialEq)]
pub enum Trit {
	True,
	False,
	Both
}

impl Trit {
	/// Returns true if self is True or Both
	pub fn is_true(self) -> bool {
		self == Trit::True || self == Trit::Both
	}

	/// Returns true if self is False or Both
	pub fn is_false(self) -> bool {
		self == Trit::False || self == Trit::Both
	}

	/// Tests if self is True
	pub fn only_true(self) -> bool {
		self == Trit::True
	}

	/// Tests if self is False
	pub fn only_false(self) -> bool {
		self == Trit::False
	}

	/// Tests if self is both
	pub fn is_both(self) -> bool {
		self == Trit::Both
	}
}