Skip to content

Commit 076a45a

Browse files
bborehamianlancetaylor
authored andcommitted
fmt: explain how Formatter interface affects verbs and flags
Formatter is mentioned further down, but it's helpful to add it amongst the verbs and flags. Background: I spent a while puzzling how "%+v" prints a stack trace for github.com/pkg/errors when this isn't documented under 'flags'. Change-Id: Ic70145902a36780147dedca568b3cf482974fc38 GitHub-Last-Rev: 6571b49 GitHub-Pull-Request: #39860 Reviewed-on: https://go-review.googlesource.com/c/go/+/240000 Reviewed-by: Rob Pike <[email protected]> Trust: Rob Pike <[email protected]> Trust: Ian Lance Taylor <[email protected]>
1 parent e08059f commit 076a45a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/fmt/doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
concrete value that it holds, and printing continues with the next rule.
151151
152152
2. If an operand implements the Formatter interface, it will
153-
be invoked. Formatter provides fine control of formatting.
153+
be invoked. In this case the interpretation of verbs and flags is
154+
controlled by that implementation.
154155
155156
3. If the %v verb is used with the # flag (%#v) and the operand
156157
implements the GoStringer interface, that will be invoked.

src/fmt/print.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ type State interface {
4747
Flag(c int) bool
4848
}
4949

50-
// Formatter is the interface implemented by values with a custom formatter.
51-
// The implementation of Format may call Sprint(f) or Fprint(f) etc.
52-
// to generate its output.
50+
// Formatter is implemented by any value that has a Format method.
51+
// The implementation controls how State and rune are interpreted,
52+
// and may call Sprint(f) or Fprint(f) etc. to generate its output.
5353
type Formatter interface {
54-
Format(f State, c rune)
54+
Format(f State, verb rune)
5555
}
5656

5757
// Stringer is implemented by any value that has a String method,

0 commit comments

Comments
 (0)