Debian Codegraph @

third_party/rust/debug_tree/src/scoped_branch.rs

raw
1 use crate::TreeBuilder;
2
3 pub struct ScopedBranch {
4 state: Option<TreeBuilder>,
5 }
6
7 impl ScopedBranch {
8 pub fn new(state: TreeBuilder) -> ScopedBranch {
9 state.enter();
10 ScopedBranch { state: Some(state) }
11 }
12 pub fn none() -> ScopedBranch {
13 ScopedBranch { state: None }
14 }
15 pub fn release(&mut self) {
16 if let Some(x) = &self.state {
17 x.exit();
18 }
19 self.state = None;
20 }
21 }
22 impl Drop for ScopedBranch {
23 fn drop(&mut self) {
24 self.release();
25 }
26 }