Implement IsBool and IsChar for Char and Bool
This commit is contained in:
parent
704c342a6f
commit
3cb1824a1b
2 changed files with 51 additions and 4 deletions
|
@ -3,10 +3,10 @@
|
|||
*/
|
||||
|
||||
use std::any::Any;
|
||||
use super::value::{Value, ValueEq};
|
||||
use super::value::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Char(char);
|
||||
pub struct Char(pub char);
|
||||
|
||||
impl Char {
|
||||
pub fn new(v: char) -> Char { Char(v) }
|
||||
|
@ -24,3 +24,26 @@ impl ValueEq for Char {
|
|||
fn as_any(&self) -> &Any { self }
|
||||
}
|
||||
|
||||
impl IsBool for Char {
|
||||
fn is_bool(&self) -> bool { false }
|
||||
}
|
||||
|
||||
impl IsChar for Char {
|
||||
fn is_char(&self) -> bool { true }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Char;
|
||||
use types::value::{IsBool, IsChar};
|
||||
|
||||
#[test]
|
||||
fn chars_are_chars() {
|
||||
assert_eq!(Char('a').is_char(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chars_are_not_bools() {
|
||||
assert_eq!(Char('a').is_bool(), false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue