title: Why Golang string.Builder String() can convert []byte to slice without a reflect.StringHeader?
body: <p>Go's strings package defines a Builder type which has a String() method</p>
  <pre><code>func (b *Builder) String() string {
      return *(*string)(unsafe.Pointer(&amp;b.buf))
  }
  </code></pre>
  <p>as reflect pacakge indicates, a byte slice is defined as a SliceHeader and an associated data block pointed by the header's Data field:</p>
  <pre><code>type SliceHeader struct {
    Data uintptr
    Len  int
    Cap  int
  }
  </code></pre>
  <p>and string is defined as a StringHeader and an associated data block pointed by the header's Data field</p>
  <pre><code>type StringHeader struct {
    Data uintptr
    Len  int
  }
  </code></pre>
  <p>the SliceHeader has 3 fields(Data, Len and Cap) and StringHeader has only 2(Data and Len),
  so how can one convert byte slice to string directly like this ?</p>
  <pre><code>*(*string)(unsafe.Pointer(&amp;buf))
  </code></pre>
  <p>in my understanding, we should code following:</p>
  <pre><code>func byte2str(b []byte) string {
    hdr := (*reflect.SliceHeader)(unsafe.Pointer(&amp;b))
    return *(*string)(unsafe.Pointer(&amp;reflect.StringHeader{Data: hdr.Data, Len: hdr.Len}))
  }
  </code></pre>