github.com/bibaroc/wingman@v0.0.2-0.20200911182922-33c2085136b1/pkg/fst/slice.go (about) 1 package fst 2 3 import ( 4 "unsafe" 5 _ "unsafe" 6 ) 7 8 func Slice(str *string) []byte { 9 s := (*stringStruct)(unsafe.Pointer(str)) 10 sl := slice{array: s.str, len: s.len, cap: s.len} 11 return *(*[]byte)(unsafe.Pointer(&sl)) 12 } 13 14 func Slc(str *string, ln int) []byte { 15 s := (*stringStruct)(unsafe.Pointer(str)) 16 sl := slice{array: s.str, len: ln, cap: ln} 17 return *(*[]byte)(unsafe.Pointer(&sl)) 18 } 19 20 type slice struct { 21 array unsafe.Pointer 22 len int 23 cap int 24 }