labview_interop/types/
boolean.rs1#[repr(transparent)]
16#[derive(PartialEq, Eq, Clone, Copy, Debug)]
17pub struct LVBool(u8);
18
19pub const LV_FALSE: LVBool = LVBool(0);
21pub const LV_TRUE: LVBool = LVBool(1);
23
24impl From<bool> for LVBool {
25 fn from(value: bool) -> Self {
26 match value {
27 true => LV_TRUE,
28 false => LV_FALSE,
29 }
30 }
31}
32
33impl From<LVBool> for bool {
34 fn from(value: LVBool) -> Self {
35 !matches!(value.0, 0)
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn test_boolean_false_to_lv_bool() {
45 let value: LVBool = false.into();
46 assert_eq!(value, LV_FALSE)
47 }
48
49 #[test]
50 fn test_boolean_true_to_lv_bool() {
51 let value: LVBool = true.into();
52 assert_eq!(value, LV_TRUE)
53 }
54
55 #[test]
56 fn test_boolean_lvfalse_to_bool() {
57 let value: bool = LV_FALSE.into();
58 assert!(!value)
59 }
60
61 #[test]
62 fn test_boolean_lvtrue_to_bool() {
63 let value: bool = LV_TRUE.into();
64 assert!(value)
65 }
66
67 #[test]
68 fn test_any_non_zero_to_bool() {
69 let value: bool = LVBool(23).into();
70 assert!(value)
71 }
72
73 #[test]
74 fn lv_bool_in_if_statement() {
75 let true_bool: bool = LV_TRUE.into();
76 let false_bool: bool = LV_FALSE.into();
77 assert!(true_bool);
78 assert!(!false_bool);
79 }
80}