ptr

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package ptr contains a small utility function for inlining pointers.

Suppose you have a struct like so:

	type Foo struct {
 	Bar *string
 }

To initialize one, you would have to write:

foo := Foo{
	Bar: new(string)
}
*foo.Bar = "foobar"

This is gross, especially for structs with a lot of members. To alleviate this, we introduce the Ptr function:

 import . "github.com/resim-ai/rerun/ptr"
	foo := Foo{
		Bar: Ptr("foobar")
	}

Why can't I just use &?

Golang forbids you from taking the address of a constant. It must be assigned to a variable, then you can take the address of that variable. Luckily, function parameters count. And since Go is garbage collected, scoping issues aren't a problem.

We recommend importing ptr as

import . "github.com/resim-ai/api-client/ptr"

so you don't have to type `ptr.Ptr`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](t T) *T

Ptr takes its argument and returns a pointer to it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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