reflectclone

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package reflectclone holds the deep-copy policy shared by the root and transform packages.

Index

Constants

View Source
const MaxDepth = 64

MaxDepth bounds recursion so a cyclic or pathologically nested value fails with an error instead of exhausting the stack.

Variables

View Source
var ErrDepthExceeded = errors.New("copy depth exceeded")

ErrDepthExceeded reports a value nested deeper than MaxDepth, or a cycle.

View Source
var ErrUnsupportedType = errors.New("unsupported type")

ErrUnsupportedType reports a type that cannot be snapshotted safely.

Functions

func Clone

func Clone(ctx context.Context, v reflect.Value, strict bool) (reflect.Value, error)

Clone returns a deep copy of v, detached from the caller's storage.

In strict mode, types that cannot be snapshotted safely (interface, func, chan, unsafe pointer) return ErrUnsupportedType instead of being shared. Schemas use strict mode for fallback values, which are stored and reused across calls and must not alias anything the caller can still mutate.

func ImmutableType

func ImmutableType(t reflect.Type) bool

ImmutableType reports whether values of t can be shared between copies instead of being duplicated.

func IsZero

func IsZero(v reflect.Value) bool

IsZero reports whether v holds its type's zero value.

reflect.Value.IsZero and time.Time.IsZero disagree for a zero instant that carries a non-nil Location: the former compares struct fields and sees a non-nil pointer, the latter does not. Shape treats "zero instant" as zero everywhere, so time.Time is special-cased.

Types

This section is empty.

Jump to

Keyboard shortcuts

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