Created
September 22, 2017 11:02
-
-
Save knzm/803fcd810e6c2df66ed627069cd10978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
type URLString string | |
type URLStrings []URLString | |
type Strings []string | |
func unsafeCastToStringSlice(x unsafe.Pointer) []string { | |
return *(*([]string))(x) | |
} | |
func (urls URLStrings) AsStrings() []string { | |
return unsafeCastToStringSlice(unsafe.Pointer(&urls)) | |
} | |
func (ss Strings) AsURLStrings() []URLString { | |
return *(*([]URLString))(unsafe.Pointer(&ss)) | |
} | |
func main1() { | |
ss := Strings{"a", "b", "c"} | |
urls := ss.AsURLStrings() | |
fmt.Println(urls) | |
} | |
func main2() { | |
urls := URLStrings{"a", "b", "c"} | |
ss := urls.AsStrings() | |
fmt.Println(ss) | |
} | |
func main() { | |
main1() | |
main2() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment