I propose that we export this interface:
// stringWriter is the interface that wraps the WriteString method.
type stringWriter interface {
WriteString(s string) (n int, err error)
}
Strictly speaking, this is not necessary. One can declare it elsewhere, or use it inline such as w.(interface{ WriteString(string) (int, error) }).
However, I still think we should export it for a number of reasons:
Writer and ByteWriter already, so I've expected io.StringWriter to exist many times in the past.If w implements a WriteString method in the godoc can be a bit confusing if one is not used to that interface and signature. If w implements StringWriter is much clearer.$ git grep 'type.*string.*interface {$'
fmt/fmt_test.go:type stringWriter interface {
io/io.go:type stringWriter interface {
net/http/h2_bundle.go:type http2stringWriter interface {
net/http/serve_test.go: type stringWriter interface {
runtime/error.go:type stringer interface {
strings/replace.go:type stringWriterIface interface {
None of these points is a dealbreaker, but they do make learning and dealing with writers clunkier than it should be.
@dvyukov suggested exporting the interface in #21718, along with adding a WriteByte function. Note, however, that the issue was closed because it was decided that the function wasn't necessary. I agree with the decision. However, the interface should be considered separately.
OK.
Change https://golang.org/cl/139457 mentions this issue: io: export StringWriter
Most helpful comment
OK.