Skip to content

Commit

Permalink
Merge pull request #57 from yongqli/master
Browse files Browse the repository at this point in the history
Support formatting parameters in Display implementations and added tests
  • Loading branch information
zbraniecki authored Feb 7, 2022
2 parents 4e4eab5 + df1e20e commit 734e563
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tinystr16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl TinyStr16 {
impl fmt::Display for TinyStr16 {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.deref())
self.deref().fmt(f)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tinystr4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl TinyStr4 {
impl fmt::Display for TinyStr4 {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.deref())
self.deref().fmt(f)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tinystr8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl TinyStr8 {
impl fmt::Display for TinyStr8 {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.deref())
self.deref().fmt(f)
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ fn tiny4_display() {
write!(result, "{}", s).unwrap();
assert_eq!(result, "abcd");
assert_eq!(format!("{}", s), "abcd");
assert_eq!(format!("{:>8}", s), format!("{:>8}", result));
}

#[test]
Expand Down Expand Up @@ -388,6 +389,7 @@ fn tiny8_display() {
write!(result, "{}", s).unwrap();
assert_eq!(result, "abcdef");
assert_eq!(format!("{}", s), "abcdef");
assert_eq!(format!("{:>8}", s), format!("{:>8}", result));
}

#[test]
Expand Down Expand Up @@ -586,6 +588,7 @@ fn tiny16_display() {
write!(result, "{}", s).unwrap();
assert_eq!(result, "abcdefghijkl");
assert_eq!(format!("{}", s), "abcdefghijkl");
assert_eq!(format!("{:>14}", s), format!("{:>14}", result));
}

#[test]
Expand Down

0 comments on commit 734e563

Please sign in to comment.