Skip to content

Commit 18fe87b

Browse files
authored
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
2 parents ae38687 + 8be7223 commit 18fe87b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/libcore/fmt/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub trait Display {
662662
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
663663
/// let val = self.0;
664664
///
665-
/// write!(f, "{:o}", val) // delegate to i32's implementation
665+
/// fmt::Octal::fmt(&val, f) // delegate to i32's implementation
666666
/// }
667667
/// }
668668
///
@@ -712,7 +712,7 @@ pub trait Octal {
712712
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
713713
/// let val = self.0;
714714
///
715-
/// write!(f, "{:b}", val) // delegate to i32's implementation
715+
/// fmt::Binary::fmt(&val, f) // delegate to i32's implementation
716716
/// }
717717
/// }
718718
///
@@ -771,7 +771,7 @@ pub trait Binary {
771771
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
772772
/// let val = self.0;
773773
///
774-
/// write!(f, "{:x}", val) // delegate to i32's implementation
774+
/// fmt::LowerHex::fmt(&val, f) // delegate to i32's implementation
775775
/// }
776776
/// }
777777
///
@@ -824,7 +824,7 @@ pub trait LowerHex {
824824
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
825825
/// let val = self.0;
826826
///
827-
/// write!(f, "{:X}", val) // delegate to i32's implementation
827+
/// fmt::UpperHex::fmt(&val, f) // delegate to i32's implementation
828828
/// }
829829
/// }
830830
///
@@ -869,7 +869,8 @@ pub trait UpperHex {
869869
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
870870
/// // use `as` to convert to a `*const T`, which implements Pointer, which we can use
871871
///
872-
/// write!(f, "{:p}", self as *const Length)
872+
/// let ptr = self as *const Self;
873+
/// fmt::Pointer::fmt(&ptr, f)
873874
/// }
874875
/// }
875876
///

0 commit comments

Comments
 (0)