1use std::fmt::{Debug, Formatter, Result};
4
5use super::*;
6
7impl<P: Debug, T: Debug> Debug for PrefixMap<P, T> {
8 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
9 DebugPrefixMap(self, 0).fmt(f)
10 }
11}
12
13struct DebugPrefixMap<'a, P, T>(&'a PrefixMap<P, T>, usize);
14
15impl<P: Debug, T: Debug> Debug for DebugPrefixMap<'_, P, T> {
16 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
17 let map = self.0;
18 let idx = self.1;
19 let node = &map.table[idx];
20 match (node.value.as_ref(), node.left, node.right) {
21 (None, None, None) => node.prefix.fmt(f),
22 (None, None, Some(child)) | (None, Some(child), None) => f
23 .debug_map()
24 .entry(&node.prefix, &Self(map, child))
25 .finish(),
26 (None, Some(left), Some(right)) => f
27 .debug_map()
28 .entry(&node.prefix, &(Self(map, left), Self(map, right)))
29 .finish(),
30 (Some(v), None, None) => f.debug_map().entry(&node.prefix, v).finish(),
31 (Some(v), None, Some(child)) | (Some(v), Some(child), None) => f
32 .debug_map()
33 .entry(&node.prefix, &(v, Self(map, child)))
34 .finish(),
35 (Some(v), Some(left), Some(right)) => f
36 .debug_map()
37 .entry(&node.prefix, &(v, Self(map, left), Self(map, right)))
38 .finish(),
39 }
40 }
41}
42
43impl<P: Debug> Debug for PrefixSet<P> {
44 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
45 DebugPrefixMap(&self.0, 0).fmt(f)
46 }
47}