ptr

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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