clone

package
v0.121.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package clone provides helpers for copying reference types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(value any) any

Any copies maps and slices that can be represented by values decoded from YAML or JSON. Other values are returned unchanged.

func Deep added in v0.117.0

func Deep[T any](dst, src *T)

Deep creates an independent copy of src into dst using reflection. It recursively copies structs, arrays, pointers, slices, maps and interface values, so that no reference-type field of dst shares storage with src. It is a no-op if either dst or src is nil.

Unexported struct fields cannot be traversed by reflection, so they are copied bitwise, exactly as a plain `*dst = *src` assignment would. Types whose unexported fields hold references (for example a struct wrapping a private slice) therefore still share that storage with src.

Cyclic references are not supported and cause unbounded recursion.

func New added in v0.117.0

func New[T any](src *T) *T

New returns a deep copy of src in a newly allocated value, or nil if src is nil. It is a convenience wrapper around Deep for callers that don't already have a destination to copy into.

func Pointer

func Pointer[T any](value *T) *T

Pointer returns an independent copy of value.

func StringAnyMap

func StringAnyMap(source map[string]any) map[string]any

StringAnyMap returns an independent copy of source, including nested maps and slices stored as values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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