mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Add a manual Debug formatter for Collection to make debugging nicer
This commit is contained in:
parent
9bf1674946
commit
3ff3695758
1 changed files with 16 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use crate::header::{AppHeader, ImportsEntry, InterfaceHeader, PlatformHeader, TypedIdent};
|
||||
use crate::ident::Ident;
|
||||
use bumpalo::collections::{String, Vec};
|
||||
|
@ -489,7 +491,7 @@ impl<'a> Pattern<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Collection<'a, T> {
|
||||
pub items: &'a [T],
|
||||
// Use a pointer to a slice (rather than just a slice), in order to avoid bloating
|
||||
|
@ -597,6 +599,19 @@ impl<'a, T: PartialEq> PartialEq for Collection<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Debug> Debug for Collection<'a, T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if self.final_comments().is_empty() {
|
||||
f.debug_list().entries(self.items.iter()).finish()
|
||||
} else {
|
||||
f.debug_struct("Collection")
|
||||
.field("items", &self.items)
|
||||
.field("final_comments", &self.final_comments())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Spaceable<'a> {
|
||||
fn before(&'a self, _: &'a [CommentOrNewline<'a>]) -> Self;
|
||||
fn after(&'a self, _: &'a [CommentOrNewline<'a>]) -> Self;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue