settings_inspect_utils/
joinable_inspect_vecdeque.rsuse fuchsia_inspect::{Node, Property, StringProperty};
use fuchsia_inspect_derive::Unit;
use std::collections::VecDeque;
#[derive(Default)]
pub struct JoinableInspectVecDeque(pub VecDeque<String>);
impl JoinableInspectVecDeque {
fn join(&self) -> String {
self.0.iter().map(String::as_str).collect::<Vec<_>>().join(",")
}
}
impl Unit for JoinableInspectVecDeque {
type Data = StringProperty;
fn inspect_create(&self, parent: &Node, name: impl AsRef<str>) -> Self::Data {
parent.create_string(name.as_ref(), self.join())
}
fn inspect_update(&self, data: &mut Self::Data) {
data.set(&self.join());
}
}
#[cfg(test)]
mod tests {
use crate::joinable_inspect_vecdeque::JoinableInspectVecDeque;
use diagnostics_assertions::assert_data_tree;
use fuchsia_inspect::{Inspector, Node};
use fuchsia_inspect_derive::{IValue, Inspect, WithInspect};
#[derive(Default, Inspect)]
struct TestInspectWrapper {
inspect_node: Node,
pub test_vec_deque: IValue<JoinableInspectVecDeque>,
}
#[fuchsia::test]
fn test_vec_deque() {
let inspector = Inspector::default();
let mut wrapper = TestInspectWrapper::default()
.with_inspect(inspector.root(), "wrapper_node")
.expect("Failed to attach wrapper_node");
wrapper.test_vec_deque.as_mut().0.push_back("test1".to_string());
wrapper.test_vec_deque.as_mut().0.push_back("test2".to_string());
wrapper.test_vec_deque.as_mut().0.push_back("test3".to_string());
let _ = wrapper.test_vec_deque.as_mut().0.pop_front();
assert_data_tree!(inspector, root: {
wrapper_node: {
"test_vec_deque": "test2,test3",
}
});
}
}