ptr

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2018 License: MIT Imports: 0 Imported by: 26

README

go-ptr

GoDoc CircleCI codecov Go Report Card GitHub last commit GitHub tag 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.

Motivation

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"))

License

MIT

Documentation

Overview

Package ptr provides functions to convert a literal value to pointer.

To be honest, this library is very trivial. If there are any other ways to get a pointer of the literal value, please tell us.

https://github.com/suzuki-shunsuke/go-ptr#motivation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PBool

func PBool(s bool) *bool

PBool returns a pointer of a given bool.

func PByte added in v1.0.0

func PByte(s byte) *byte

PByte returns a pocomplexer of a given byte.

func PComplex128 added in v1.0.0

func PComplex128(s complex128) *complex128

PComplex128 returns a pocomplexer of a given complex128.

func PComplex64 added in v1.0.0

func PComplex64(s complex64) *complex64

PComplex64 returns a pocomplexer of a given complex64.

func PFloat32 added in v1.0.0

func PFloat32(s float32) *float32

PFloat32 returns a pofloater of a given float32.

func PFloat64 added in v1.0.0

func PFloat64(s float64) *float64

PFloat64 returns a pofloater of a given float64.

func PInt

func PInt(s int) *int

PInt returns a pointer of a given int.

func PInt16 added in v1.0.0

func PInt16(s int16) *int16

PInt16 returns a pointer of a given int16.

func PInt32 added in v1.0.0

func PInt32(s int32) *int32

PInt32 returns a pointer of a given int32.

func PInt64 added in v1.0.0

func PInt64(s int64) *int64

PInt64 returns a pointer of a given int64.

func PInt8 added in v1.0.0

func PInt8(s int8) *int8

PInt8 returns a pointer of a given int8.

func PRune added in v1.0.0

func PRune(s rune) *rune

PRune returns a pocomplexer of a given rune.

func PStr

func PStr(s string) *string

PStr returns a pointer of a given string.

func PUint added in v1.0.0

func PUint(s uint) *uint

PUint returns a pointer of a given uint.

func PUint16 added in v1.0.0

func PUint16(s uint16) *uint16

PUint16 returns a pointer of a given uint16.

func PUint32 added in v1.0.0

func PUint32(s uint32) *uint32

PUint32 returns a pointer of a given uint32.

func PUint64 added in v1.0.0

func PUint64(s uint64) *uint64

PUint64 returns a pointer of a given uint64.

func PUint8 added in v1.0.0

func PUint8(s uint8) *uint8

PUint8 returns a pointer of a given uint8.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL