Source file src/internal/unsafeheader/unsafeheader.go
1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package unsafeheader contains header declarations for the Go runtime's slice 6 // and string implementations. 7 // 8 // This package allows packages that cannot import "reflect" to use types that 9 // are tested to be equivalent to reflect.SliceHeader and reflect.StringHeader. 10 package unsafeheader 11 12 import ( 13 "unsafe" 14 ) 15 16 // Slice is the runtime representation of a slice. 17 // It cannot be used safely or portably and its representation may 18 // change in a later release. 19 // 20 // Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the 21 // data it references will not be garbage collected. 22 type Slice struct { 23 Data unsafe.Pointer 24 Len int 25 Cap int 26 } 27 28 // String is the runtime representation of a string. 29 // It cannot be used safely or portably and its representation may 30 // change in a later release. 31 // 32 // Unlike reflect.StringHeader, its Data field is sufficient to guarantee the 33 // data it references will not be garbage collected. 34 type String struct { 35 Data unsafe.Pointer 36 Len int 37 } 38