Skip to content

Commit b785403

Browse files
Philippe-Choletjswrenn
authored andcommitted
ExactlyOneError: implement Debug differently
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!`.
1 parent 7a1c22b commit b785403

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/exactly_one_err.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,17 @@ where
102102
I::Item: Debug,
103103
{
104104
fn fmt(&self, f: &mut Formatter) -> FmtResult {
105+
let mut dbg = f.debug_struct("ExactlyOneError");
105106
match &self.first_two {
106107
Some(Either::Left([first, second])) => {
107-
write!(
108-
f,
109-
"ExactlyOneError[First: {:?}, Second: {:?}, RemainingIter: {:?}]",
110-
first, second, self.inner
111-
)
108+
dbg.field("first", first).field("second", second);
112109
}
113110
Some(Either::Right(second)) => {
114-
write!(
115-
f,
116-
"ExactlyOneError[Second: {:?}, RemainingIter: {:?}]",
117-
second, self.inner
118-
)
119-
}
120-
None => {
121-
write!(f, "ExactlyOneError[RemainingIter: {:?}]", self.inner)
111+
dbg.field("second", second);
122112
}
113+
None => {}
123114
}
115+
dbg.field("inner", &self.inner).finish()
124116
}
125117
}
126118

0 commit comments

Comments
 (0)