golang library to convert a literal to pointer
MIT License
golang library to convert a literal to pointer.
This library is very trivial. If there are any other ways to get a pointer of the literal value, please tell us.
Sometimes we want to get a pointer of the literal value. But the following code raises a compile error.
https://play.golang.org/p/p9E9omKHogv
package main
import (
"fmt"
)
func main() {
fmt.Println(&"hello")
}
prog.go:8:14: cannot take the address of "hello"
So we have to assign the literal to a variable.
a := "hello"
fmt.Println(&a)
But we want to write this at an one liner.
fmt.Println(ptr.PStr("hello"))