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





use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result;

use crate::_Object;


/// Bool structure for True and False
#[derive(Copy, Clone)]
pub struct Bool {
    _bool: bool
}

impl Bool {
    /// create a new bool
    /// example
    /// let boolean = Bool::new(true)
    /// let boolean = Bool::new(false)
    pub fn new(_bool: bool) -> Bool {
        Bool {
            _bool
        }
    }
}

impl _Object for Bool {
    fn __str__(&self) -> String {
        if self._bool {
            format!("True")
        } else {
            format!("False")
        }
    }

    fn __len__(&self) -> usize {
        8
    }

    fn __repr__(&self) -> String {
        self.__str__()
    }
}

impl Display for Bool {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "{}", self.__str__())
    }
}