I would expect that `println!("{:_>4}", [1].as_slice());` would print either
`[___1]` (where the format is "mapped" over the slice) or `_[1]` (where the
format is applied to the slice as a whole), but instead no formatting is
applied at all and it simply prints `[1]`.
I can see uses and arguments for both the "mapping" and "whole” interpretations
of the format string on slices. On the one hand this ambiguity makes a case for
leaving the behavior as-is for backwards compatibility. On the other hand it
would be useful to be able to format slices (and other collections, of course).
Would it be appropriate to expand the syntax for format strings to allow for
nested format strings, so that separate formatting can be applied to the entire
collection and to its contents? I assume it this would require an RFC.
(The "mapped" variant can be very easily implemented, by the way, by replacing
`try!(write!("{}", x))` with `try!(x.fmt(f))` in the `impl<T: Show> Show for
&[T]`.)
Tom
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev