diff options
| author | bors <bors@rust-lang.org> | 2018-03-19 02:38:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-19 02:38:19 +0000 |
| commit | 152217d29cc842d9a7577e9361f5960f87dcdf5c (patch) | |
| tree | f54d4e5fbd697c667903e774bf53bd0916ed908b /src/liballoc | |
| parent | c2f4744d2db4e162df824d0bd0b093ba4b351545 (diff) | |
| parent | 4897935e8645e5f1d9d9ef61c78a1cb019c44f89 (diff) | |
| download | rust-152217d29cc842d9a7577e9361f5960f87dcdf5c.tar.gz rust-152217d29cc842d9a7577e9361f5960f87dcdf5c.zip | |
Auto merge of #48978 - SimonSapin:debug-hex, r=KodrAus
Add hexadecimal formatting of integers with fmt::Debug
This can be used for integers within a larger types which implements Debug (possibly through derive) but not fmt::UpperHex or fmt::LowerHex.
```rust
assert!(format!("{:02x?}", b"Foo\0") == "[46, 6f, 6f, 00]");
assert!(format!("{:02X?}", b"Foo\0") == "[46, 6F, 6F, 00]");
```
RFC: https://github.com/rust-lang/rfcs/pull/2226
The new formatting string syntax (`x?` and `X?`) is insta-stable in this PR because I don’t know how to change a built-in proc macro’s behavior based of a feature gate. I can look into adding that, but I also strongly suspect that keeping this feature unstable for a time period would not be useful as possibly no-one would use it during that time.
This PR does not add the new (public) `fmt::Formatter` proposed in the API because:
* There was some skepticism on response to this part of the RFC
* It is not possible to implement as-is without larger changes to `fmt`, because `Formatter` at the moment has no easy way to tell apart for example `Octal` from `Binary`: it only has a function pointer for the relevant `fmt()` method.
If some integer-like type outside of `std` want to implement this behavior, another RFC will likely need to propose a different public API for `Formatter`.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/fmt.rs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/liballoc/fmt.rs b/src/liballoc/fmt.rs index a092bfb3b0a..2c4cdef03b0 100644 --- a/src/liballoc/fmt.rs +++ b/src/liballoc/fmt.rs @@ -113,6 +113,8 @@ //! //! * *nothing* ⇒ [`Display`] //! * `?` ⇒ [`Debug`] +//! * `x?` ⇒ [`Debug`] with lower-case hexadecimal integers +//! * `X?` ⇒ [`Debug`] with lower-case hexadecimal integers //! * `o` ⇒ [`Octal`](trait.Octal.html) //! * `x` ⇒ [`LowerHex`](trait.LowerHex.html) //! * `X` ⇒ [`UpperHex`](trait.UpperHex.html) |
