auto merge of #15281 : alexcrichton/rust/show-for-show, r=kballard
This makes printing a `Show` trait object much easier.
This commit is contained in:
commit
d968340671
|
@ -518,6 +518,9 @@ impl<'a, T: Show> Show for &'a T {
|
||||||
impl<'a, T: Show> Show for &'a mut T {
|
impl<'a, T: Show> Show for &'a mut T {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
|
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
|
||||||
}
|
}
|
||||||
|
impl<'a> Show for &'a Show {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
|
||||||
|
}
|
||||||
|
|
||||||
impl Bool for bool {
|
impl Bool for bool {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
|
|
|
@ -81,6 +81,9 @@ pub fn main() {
|
||||||
t!(format!("{foo_bar}", foo_bar=1i), "1");
|
t!(format!("{foo_bar}", foo_bar=1i), "1");
|
||||||
t!(format!("{:d}", 5i + 5i), "10");
|
t!(format!("{:d}", 5i + 5i), "10");
|
||||||
|
|
||||||
|
let a: &fmt::Show = &1i;
|
||||||
|
t!(format!("{}", a), "1");
|
||||||
|
|
||||||
// Formatting strings and their arguments
|
// Formatting strings and their arguments
|
||||||
t!(format!("{:s}", "a"), "a");
|
t!(format!("{:s}", "a"), "a");
|
||||||
t!(format!("{:4s}", "a"), "a ");
|
t!(format!("{:4s}", "a"), "a ");
|
||||||
|
|
Loading…
Reference in New Issue