Skip to content

Commit 9a3519e

Browse files
authored
Merge pull request mozilla#225 from kornelski/debugfmt
Improve debug format implementations
2 parents d5a37fd + c04bcfd commit 9a3519e

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

mp4parse/src/boxes.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! box_database {
4444
impl fmt::Debug for BoxType {
4545
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4646
let fourcc: FourCC = From::from(self.clone());
47-
write!(f, "{}", fourcc)
47+
fourcc.fmt(f)
4848
}
4949
}
5050
}
@@ -79,18 +79,15 @@ impl From<[u8; 4]> for FourCC {
7979
impl fmt::Debug for FourCC {
8080
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8181
match std::str::from_utf8(&self.value) {
82-
Ok(s) => write!(f, "{}", s),
82+
Ok(s) => f.write_str(s),
8383
Err(_) => self.value.fmt(f),
8484
}
8585
}
8686
}
8787

8888
impl fmt::Display for FourCC {
8989
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90-
match std::str::from_utf8(&self.value) {
91-
Ok(s) => write!(f, "{}", s),
92-
Err(_) => write!(f, "null"),
93-
}
90+
f.write_str(std::str::from_utf8(&self.value).unwrap_or("null"))
9491
}
9592
}
9693

mp4parse/src/fallible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub struct TryVec<T> {
188188

189189
impl<T: std::fmt::Debug> std::fmt::Debug for TryVec<T> {
190190
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
191-
write!(f, "{:?}", self.inner)
191+
self.inner.fmt(f)
192192
}
193193
}
194194

mp4parse/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ struct U32BE(u32);
14551455
impl std::fmt::Display for U32BE {
14561456
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14571457
match std::str::from_utf8(&self.0.to_be_bytes()) {
1458-
Ok(s) => write!(f, "{}", s),
1458+
Ok(s) => f.write_str(s),
14591459
Err(_) => write!(f, "{:x?}", self.0),
14601460
}
14611461
}

0 commit comments

Comments
 (0)