wezterm_dynamic/
drop.rs

1use crate::Value;
2
3/// Non-recursive drop implementation.
4/// This is taken from dtolnay's miniserde library
5/// and is reproduced here under the terms of its
6/// MIT license
7pub fn safely(value: Value) {
8    match value {
9        Value::Array(_) | Value::Object(_) => {}
10        _ => return,
11    }
12
13    let mut stack = Vec::new();
14    stack.push(value);
15    while let Some(value) = stack.pop() {
16        match value {
17            Value::Array(vec) => {
18                for child in vec {
19                    stack.push(child);
20                }
21            }
22            Value::Object(map) => {
23                for (_, child) in map {
24                    stack.push(child);
25                }
26            }
27            _ => {}
28        }
29    }
30}