summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2019-12-06 15:37:10 +0900
committerGitHub <noreply@github.com>2019-12-06 15:37:10 +0900
commitf7c2631d4a161563edb3eb142a8b0b2d1429ab5c (patch)
treee724eea90db5c3941e5c2cc35fadcebb7180df16
parentRollup merge of #67017 - GuillaumeGomez:long-err-explanations-2, r=Dylan-DPC (diff)
parentFix docs for formatting delegations (diff)
downloadrust-f7c2631d4a161563edb3eb142a8b0b2d1429ab5c.tar.gz
rust-f7c2631d4a161563edb3eb142a8b0b2d1429ab5c.tar.bz2
rust-f7c2631d4a161563edb3eb142a8b0b2d1429ab5c.tar.xz
Rollup merge of #67021 - elichai:2019-12-fmt, r=QuietMisdreavus
Fix docs for formatting delegations If you use the example in the docs right now it breaks all the options Formatters have to offer. i.e. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=214392ecc6eff73b4789c32568395f72 this should've padded the output with 4 zeros but didn't. with the new example it does work: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3bdfb29f395230c5129c5f56dcfcb2a9 The only thing i'm not quite sure about is what's the right way to do it in a loop (altough non of the docs talk about it people are doing it in the wild and there were a couple of attempts to include in libcore) i.e. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4c4dca3c90ba36779ecd014f3899ab9c
-rw-r--r--src/libcore/fmt/mod.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index 4c941e2..e2f49ee 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -662,7 +662,7 @@ pub trait Display {
662/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 662/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
663/// let val = self.0; 663/// let val = self.0;
664/// 664///
665/// write!(f, "{:o}", val) // delegate to i32's implementation 665/// fmt::Octal::fmt(&val, f) // delegate to i32's implementation
666/// } 666/// }
667/// } 667/// }
668/// 668///
@@ -712,7 +712,7 @@ pub trait Octal {
712/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 712/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
713/// let val = self.0; 713/// let val = self.0;
714/// 714///
715/// write!(f, "{:b}", val) // delegate to i32's implementation 715/// fmt::Binary::fmt(&val, f) // delegate to i32's implementation
716/// } 716/// }
717/// } 717/// }
718/// 718///
@@ -771,7 +771,7 @@ pub trait Binary {
771/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 771/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
772/// let val = self.0; 772/// let val = self.0;
773/// 773///
774/// write!(f, "{:x}", val) // delegate to i32's implementation 774/// fmt::LowerHex::fmt(&val, f) // delegate to i32's implementation
775/// } 775/// }
776/// } 776/// }
777/// 777///
@@ -824,7 +824,7 @@ pub trait LowerHex {
824/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 824/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
825/// let val = self.0; 825/// let val = self.0;
826/// 826///
827/// write!(f, "{:X}", val) // delegate to i32's implementation 827/// fmt::UpperHex::fmt(&val, f) // delegate to i32's implementation
828/// } 828/// }
829/// } 829/// }
830/// 830///
@@ -869,7 +869,8 @@ pub trait UpperHex {
869/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 869/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
870/// // use `as` to convert to a `*const T`, which implements Pointer, which we can use 870/// // use `as` to convert to a `*const T`, which implements Pointer, which we can use
871/// 871///
872/// write!(f, "{:p}", self as *const Length) 872/// let ptr = self as *const Self;
873/// fmt::Pointer::fmt(&ptr, f)
873/// } 874/// }
874/// } 875/// }
875/// 876///