@@ -106,35 +106,31 @@ named parameters that are unused by the format string.
106106
107107### Argument types
108108
109- Each argument's type is dictated by the format string. It is a requirement that
110- every argument is only ever referred to by one type. For example, this is an
111- invalid format string:
109+ Each argument's type is dictated by the format string. It is a requirement that every argument is
110+ only ever referred to by one type. For example, this is an invalid format string:
112111
113112```text
114- {0:d } {0:s }
113+ {0:x } {0:o }
115114```
116115
117- This is invalid because the first argument is both referred to as an integer as
118- well as a string .
116+ This is invalid because the first argument is both referred to as a hexidecimal as well as an
117+ octal .
119118
120- Because formatting is done via traits, there is no requirement that the
121- `d` format actually takes an `int`, but rather it simply requires a type which
122- ascribes to the `Signed` formatting trait. There are various parameters which do
123- require a particular type, however. Namely if the syntax `{:.*s}` is used, then
124- the number of characters to print from the string precedes the actual string and
125- must have the type `uint`. Although a `uint` can be printed with `{:u}`, it is
126- illegal to reference an argument as such. For example, this is another invalid
119+ There are various parameters which do require a particular type, however. Namely if the syntax
120+ `{:.*}` is used, then the number of characters to print precedes the actual object being formatted,
121+ and the number of characters must have the type `uint`. Although a `uint` can be printed with
122+ `{}`, it is illegal to reference an argument as such. For example this is another invalid
127123format string:
128124
129125```text
130- {:.*s } {0:u }
126+ {:.*} {0}
131127```
132128
133129### Formatting traits
134130
135131When requesting that an argument be formatted with a particular type, you are
136132actually requesting that an argument ascribes to a particular trait. This allows
137- multiple actual types to be formatted via `{:d }` (like `i8` as well as `int`).
133+ multiple actual types to be formatted via `{:x }` (like `i8` as well as `int`).
138134The current mapping of types to traits is:
139135
140136* *nothing* ⇒ `Show`
@@ -157,12 +153,12 @@ When implementing a format trait for your own type, you will have to implement a
157153method of the signature:
158154
159155```rust
160- # use std;
161- # mod fmt { pub type Result = (); }
162- # struct T;
163- # trait SomeName<T> {
164- fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result;
165- # }
156+ # use std::fmt ;
157+ # struct Foo; // our custom type
158+ # impl fmt::Show for Foo {
159+ fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
160+ # write!(f, "testing, testing")
161+ # } }
166162```
167163
168164Your type will be passed as `self` by-reference, and then the function should
@@ -237,7 +233,6 @@ println! // same as print but appends a newline
237233format_args! // described below.
238234```
239235
240-
241236#### `write!`
242237
243238This and `writeln` are two macros which are used to emit the format string to a
0 commit comments