Closed aDotInTheVoid closed 4 months ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/combinator/debug/internals.rs | 0 | 1 | 0.0% | ||
<!-- | Total: | 0 | 1 | 0.0% | --> |
Totals | |
---|---|
Change from base Build 8854777459: | 0.03% |
Covered Lines: | 1277 |
Relevant Lines: | 3069 |
Ah, (ab)using f.alterante()
to switch input works
impl fmt::Debug for Input<'_, '_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
let toks = self.remaining_input();
// Don't use Debug::fmt(f, toks) to force non-alternate writing, see winnow#516
write!(f, "{toks:?}")
} else {
f.debug_struct("Input")
.field("source", &self.source)
.field("offset", &self.offset)
.field("acx", &self.acx)
.finish()
}
}
}
(where .remaining_input()
returns the slice still to be parsed).
It does unfortunatly mean that dbg!(i)
won't show the offset, but I think it's a good tradeoff for me for now.
See also https://github.com/winnow-rs/winnow/issues/482#issuecomment-2094500462, for some thaughts on a potential change to Stream
to make this easier
If the Input type is a slice, using
{:#?}
will insert newlines into the debug view. This messes up the output, which is counting charecters to fill a single line.Before:
After: