apimachineryk8s.io/apimachinery/pkg/api/safe Index | Files

package safe

import "k8s.io/apimachinery/pkg/api/safe"

Index

Functions

func Cast

func Cast[T any](value any) T

Cast takes any value, attempts to cast it to T, and returns the T value if the cast is successful, or else the zero value of T.

func Field

func Field[V any, R any](value *V, fn func(*V) R) R

Field takes a pointer to any value (which may or may not be nil) and a function that traverses to a target type R (a typical use case is to dereference a field), and returns the result of the traversal, or the zero value of the target type. This is roughly equivalent to "value != nil ? fn(value) : zero-value" in languages that support the ternary operator.

Source Files

safe.go

Version
v0.33.0 (latest)
Published
Apr 11, 2025
Platform
linux/amd64
Last checked
14 minutes ago

Tools for package owners.