Make debug printing of Node less verbose

pull/25/head
Wilfred Hughes 2021-07-02 18:14:13 +07:00
parent b956f0da1d
commit 57dc746d84
1 changed files with 27 additions and 2 deletions

@ -1,5 +1,4 @@
#![allow(clippy::mutable_key_type)] // Hash for Node doesn't use mutable fields. #![allow(clippy::mutable_key_type)] // Hash for Node doesn't use mutable fields.
#![allow(dead_code)] #![allow(dead_code)]
use diff::{slice, Result::*}; use diff::{slice, Result::*};
@ -45,7 +44,6 @@ pub enum AtomKind {
Other, Other,
} }
#[derive(Debug)]
pub enum Node<'a> { pub enum Node<'a> {
List { List {
next: Cell<Option<&'a Node<'a>>>, next: Cell<Option<&'a Node<'a>>>,
@ -66,6 +64,33 @@ pub enum Node<'a> {
}, },
} }
impl<'a> fmt::Debug for Node<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
List {
open_delimiter,
children,
close_delimiter,
change,
..
} => f
.debug_struct("List")
.field("open_delimiter", &open_delimiter)
.field("children", &children)
.field("close_delimiter", &close_delimiter)
.field("change", &change)
.finish(),
Atom {
content, change, ..
} => f
.debug_struct("Atom")
.field("content", &content)
.field("change", &change)
.finish(),
}
}
}
impl<'a> Node<'a> { impl<'a> Node<'a> {
#[allow(clippy::clippy::mut_from_ref)] // Clippy doesn't understand arenas. #[allow(clippy::clippy::mut_from_ref)] // Clippy doesn't understand arenas.
pub fn new_list( pub fn new_list(