gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/strings/unsafe/unsafe.go (about) 1 package unsafe 2 3 import "unsafe" 4 5 type String struct { 6 Ptr unsafe.Pointer 7 Len int 8 } 9 10 type slice struct { 11 string 12 cap int 13 } 14 15 func Bytes(s string) (bs []byte) { 16 *(*slice)(unsafe.Pointer(&bs)) = slice{string: s, cap: len(s)} 17 return 18 }