Skip to content

candiduslynx/ptr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ptr

Simple pointer helpers for Go

Go Reference

Obtaining pointer to the value

Simply pass the value to the To function, the type will be inferred by the Go compiler.

p := ptr.To(float32(0.5)) // p is *float32 pointing to the value 0.5

Retrieving value designated by pointer

To retrieve the value designated by pointer simply pass the pointer to From function. If the pointer might be nil you can supply optional default value as well. if the pointer is nil and default value isn't provided, From will panic.

// panics
_ = ptr.From((*float32)(nil))

var vv = float32(0.5)
value = ptr.From(&vv) // value = float32(0.5)
value = ptr.From((*float32)(nil), 0.7) // value = float32(0.7)

About

Simple pointer helpers for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages