aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2018-10-03 21:01:14 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2018-10-03 20:13:35 +0000
commit112f28defcbd8f48de83f4502093ac97149b4da6 (patch)
treedc91268f72f65c2ba28e95501a85156a1834f4e1 /src/io
parentc91ce3cc7b13fce23edae94818e505f126036bdb (diff)
downloadgo-112f28defcbd8f48de83f4502093ac97149b4da6.tar.gz
go-112f28defcbd8f48de83f4502093ac97149b4da6.zip
io: export StringWriter
And start using it elsewhere in the standard library, removing the copies in the process. While at it, rewrite the io.WriteString godoc to be more clear, since it can now make reference to the defined interface. Fixes #27946. Change-Id: Id5ba223c09c19e5fb49815bd3b1bd3254fc786f3 Reviewed-on: https://go-review.googlesource.com/c/139457 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/io')
-rw-r--r--src/io/io.go8
-rw-r--r--src/io/multi.go4
2 files changed, 6 insertions, 6 deletions
diff --git a/src/io/io.go b/src/io/io.go
index 72b75813a5..2010770e6a 100644
--- a/src/io/io.go
+++ b/src/io/io.go
@@ -278,16 +278,16 @@ type RuneScanner interface {
UnreadRune() error
}
-// stringWriter is the interface that wraps the WriteString method.
-type stringWriter interface {
+// StringWriter is the interface that wraps the WriteString method.
+type StringWriter interface {
WriteString(s string) (n int, err error)
}
// WriteString writes the contents of the string s to w, which accepts a slice of bytes.
-// If w implements a WriteString method, it is invoked directly.
+// If w implements StringWriter, its WriteString method is invoked directly.
// Otherwise, w.Write is called exactly once.
func WriteString(w Writer, s string) (n int, err error) {
- if sw, ok := w.(stringWriter); ok {
+ if sw, ok := w.(StringWriter); ok {
return sw.WriteString(s)
}
return w.Write([]byte(s))
diff --git a/src/io/multi.go b/src/io/multi.go
index 65f99099ca..24ee71e4ca 100644
--- a/src/io/multi.go
+++ b/src/io/multi.go
@@ -69,12 +69,12 @@ func (t *multiWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
-var _ stringWriter = (*multiWriter)(nil)
+var _ StringWriter = (*multiWriter)(nil)
func (t *multiWriter) WriteString(s string) (n int, err error) {
var p []byte // lazily initialized if/when needed
for _, w := range t.writers {
- if sw, ok := w.(stringWriter); ok {
+ if sw, ok := w.(StringWriter); ok {
n, err = sw.WriteString(s)
} else {
if p == nil {