fuchsia_inspect/writer/types/
bool_property.rs1use crate::writer::{Inner, InnerValueType, InspectType, Property};
6
7#[derive(Debug, PartialEq, Eq, Default)]
14pub struct BoolProperty {
15 inner: Inner<InnerValueType>,
16}
17
18impl Property<'_> for BoolProperty {
19 type Type = bool;
20
21 fn set(&self, value: bool) {
22 if let Some(ref inner_ref) = self.inner.inner_ref() {
23 if let Ok(mut state) = inner_ref.state.try_lock() {
24 state.set_bool(inner_ref.block_index, value);
25 }
26 }
27 }
28}
29
30impl InspectType for BoolProperty {}
31
32crate::impl_inspect_type_internal!(BoolProperty);
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use crate::writer::testing_utils::{get_state, GetBlockExt};
38 use crate::writer::Node;
39 use inspect_format::{BlockType, Bool};
40
41 #[fuchsia::test]
42 fn bool_property() {
43 let default = BoolProperty::default();
45 default.set(true);
46
47 let state = get_state(4096);
48 let root = Node::new_root(state);
49 let node = root.create_child("node");
50 {
51 let property = node.create_bool("property", true);
52 property.get_block::<_, Bool>(|block| {
53 assert_eq!(block.block_type(), Some(BlockType::BoolValue));
54 assert!(block.value());
55 });
56 node.get_block::<_, inspect_format::Node>(|block| {
57 assert_eq!(block.child_count(), 1);
58 });
59
60 property.set(false);
61 property.get_block::<_, Bool>(|block| {
62 assert!(!block.value());
63 });
64 }
65 node.get_block::<_, inspect_format::Node>(|block| {
66 assert_eq!(block.child_count(), 0);
67 });
68 }
69}