1use num::Float;
2use crate::{HType, HVal, NumTrait};
3use crate::common::Txt;
4use std::fmt::{self,Write,Display};
5use std::str::FromStr;
6
7#[derive(PartialEq,Debug,Clone)]
8pub struct HBool(pub bool);
9
10pub type Bool = HBool;
11
12const ZINC_TRUE: Txt = Txt::Const("T");
13const ZINC_FALSE: Txt = Txt::Const("F");
14
15const JSON_TRUE: Txt = Txt::Const("true");
16const JSON_FALSE: Txt = Txt::Const("false");
17
18const THIS_TYPE: HType = HType::Bool;
19
20impl <'a,T: NumTrait + 'a>HVal<'a,T> for HBool {
21 fn to_zinc(&self, buf: &mut String) -> fmt::Result {
22 match self.0 {
23 true => write!(buf,"{}",ZINC_TRUE),
24 false => write!(buf,"{}",ZINC_FALSE),
25 }
26 }
27 fn to_json(&self, buf: &mut String) -> fmt::Result {
28 match self.0 {
29 true => write!(buf,"{}",JSON_TRUE),
30 false => write!(buf,"{}",JSON_FALSE),
31 }
32 }
33 fn haystack_type(&self) -> HType { THIS_TYPE }
34
35 set_trait_eq_method!(get_bool_val,'a,T);
36 set_get_method!(get_bool_val, HBool);
37}