Standard library / io

io.WriterTo

Optional bulk output interface; io.Copy prefers source WriterTo over destination ReaderFrom. Expected stdout: '3 abc <nil>\n'.

Formal Syntax & Structure

go syntaxgo
type WriterTo interface {  WriteTo(w Writer) (n int64, err error)}

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "io"  "strings")
func main() {  var w io.WriterTo = strings.NewReader("abc")  var b bytes.Buffer  n, e := w.WriteTo(&b)  fmt.Println(n, b.String(), e)}
Go Reference