Skip to content

Commit

Permalink
ExactlyOneError: implement Debug differently
Browse files Browse the repository at this point in the history
It could be derived. It apparently was decided not to in #484, probably to not leak implementation details that could confuse the user.
However, it would not render well for pretty formats such as `"{:#?}"`. I think we should call methods on `f` instead of using `write!`.
  • Loading branch information
Philippe-Cholet authored and jswrenn committed Jan 24, 2024
1 parent 7a1c22b commit b785403
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/exactly_one_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,17 @@ where
I::Item: Debug,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
let mut dbg = f.debug_struct("ExactlyOneError");
match &self.first_two {
Some(Either::Left([first, second])) => {
write!(
f,
"ExactlyOneError[First: {:?}, Second: {:?}, RemainingIter: {:?}]",
first, second, self.inner
)
dbg.field("first", first).field("second", second);
}
Some(Either::Right(second)) => {
write!(
f,
"ExactlyOneError[Second: {:?}, RemainingIter: {:?}]",
second, self.inner
)
}
None => {
write!(f, "ExactlyOneError[RemainingIter: {:?}]", self.inner)
dbg.field("second", second);
}
None => {}
}
dbg.field("inner", &self.inner).finish()
}
}

Expand Down

0 comments on commit b785403

Please sign in to comment.