Skip to content

chrisdoherty4/ptr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ptr

Package ptr provides utility functions for converting non-addressable primitive types to pointers. Its useful in contexts where a variable gives nil primitive type pointers semantics (often meaning "not set") which can make it annoying to set the value.

Look at ptr.go for the suite of functions. We recommend using the To function for everything unless you can find a really good reason not to.

Example

type Foo struct {
    A *int
}

func main() {
    foo := Foo{
        A: ptr.To(1)
    }
}

Copy it, don't import it

Given the simplicity of this package, I recommend copying it to your source tree to avoid an unnecessary depedency.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages