clone

package
v0.0.0-...-6d78eec Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package clone creates deep copies (as opposed to shallow copies).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsImmutableType

func AsImmutableType(example any)

AsImmutableType declares the type of the example value as immutable.

  • Immutable types will be shallow-copied instead of deep-copied.
  • Only struct types can be declared to be immutable. Attempting to pass an example for a non-struct type will result in a panic.
  • Cloning a value of an immutable type will never panic, even if it has unexported fields.
  • This function is idempotent for multiple values of the same underlying type. In other words, it will not fail if a type has already been flagged as immutable.

func Of

func Of[T any](x T) T

Of returns a clone (AKA deep copy) of the passed object.

This function will panic if any of the below conditions are met:

  • The value is or contains a channel.
  • The value is or contains a function.
  • The value is or contains an unsafe pointer.
  • The value is or contains a struct with unexported fields, except if that struct that has been marked with AsImmutableType or the size of the field is zero (in order to allow unexported traits).

Types

This section is empty.

Jump to

Keyboard shortcuts

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