Skip to main content

bel/common/types/
bool.rs

1use std::any::Any;
2
3use crate::common::{types::Type, value::Val};
4
5#[derive(Clone, Debug, PartialEq)]
6pub struct Bool(bool);
7
8impl Val for Bool {
9    fn get_type(&self) -> Type<'_> {
10        super::BOOL_TYPE
11    }
12
13    fn into_inner(self) -> Box<dyn Any> {
14        Box::new(self.0)
15    }
16}
17
18impl From<Bool> for bool {
19    fn from(value: Bool) -> Self {
20        value.0
21    }
22}
23
24impl From<bool> for Bool {
25    fn from(value: bool) -> Self {
26        Bool(value)
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33    use crate::common::{types, types::Kind};
34
35    #[test]
36    fn test_from() {
37        let value: Bool = true.into();
38        let v: bool = value.into();
39        assert!(v)
40    }
41
42    #[test]
43    fn test_type() {
44        let value = Bool(true);
45        assert_eq!(value.get_type(), types::BOOL_TYPE);
46        assert_eq!(value.get_type().kind, Kind::Boolean);
47    }
48
49    #[test]
50    fn test_into_inner() {
51        let value = Bool(true);
52        let inner = value.into_inner();
53        let option = inner.downcast::<bool>();
54        let b = option.unwrap();
55        assert!(*b);
56    }
57}