The string writer

A byte buffer executes a copy of the bytes in order to produce a string. This is why, in version 1.10, strings.Builder made its debut. It shares all the write-related methods of a buffer and does not allow access to the underlying slice via the Bytes method. The only way of obtaining the final string is with the String method, which uses the unsafe package under the hood to convert the slice to a string without copying the underlying data. 

The main consequence of this is that this struct strongly discourages copying—that's because the underlying slice of the copied slice points to the same array, and writing in the copy would influence the other one. The resulting operation would panic:

package main

import (
"strings"
)

func main() {
b := strings.Builder{}
b.WriteString("One")
c := b
c.WriteString("Hey!") // panic: strings: illegal use of non-zero Builder copied by value
}