Skip to content

Commit 1092744

Browse files
committed
Implement {:s} for ~str and @str as well
1 parent 680eb71 commit 1092744

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/libstd/fmt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ impl Bool for bool {
726726
}
727727
}
728728

729-
impl<'self> String for &'self str {
730-
fn fmt(s: & &'self str, f: &mut Formatter) {
731-
f.pad(*s);
729+
impl<'self, T: str::Str> String for T {
730+
fn fmt(s: &T, f: &mut Formatter) {
731+
f.pad(s.as_slice());
732732
}
733733
}
734734

src/test/run-pass/ifmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub fn main() {
4545
t!(ifmt!("{:x}", 10u), "a");
4646
t!(ifmt!("{:X}", 10u), "A");
4747
t!(ifmt!("{:s}", "foo"), "foo");
48+
t!(ifmt!("{:s}", ~"foo"), "foo");
49+
t!(ifmt!("{:s}", @"foo"), "foo");
4850
t!(ifmt!("{:p}", 0x1234 as *int), "0x1234");
4951
t!(ifmt!("{:p}", 0x1234 as *mut int), "0x1234");
5052
t!(ifmt!("{:d}", A), "aloha");

0 commit comments

Comments
 (0)