deep

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 3 Imported by: 27

README

deep

Support for doing deep copies of (almost all) Go types.

This is a from scratch implementation of the ideas from https://github.com/barkimedes/go-deepcopy (which, unfortunatelly appears to be dead) but it should be faster for most cases (*), simpler to use for callers and supports copying unexported fields.

It should support most Go types. Specificaly, it does not support functions, channels and unsafe.Pointers unless they are nil. Also it might have weird interations with structs that includes any synchronization primitives (mutexes, for example. They should still be copied but if they are usable after that is left as an exercise to the user).

(*) In my machine (8-Core Intel Atom NAS, running in a Linux conainer):

go-deepcopy:

BenchmarkCopy-8 84931 21655 ns/op 1912 B/op 50 allocs/op

deep:

BenchmarkCopy-8 104366 17450 ns/op 1824 B/op 43 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy[T any](src T) (T, error)

Copy creates a deep copy of src. It returns the copy and a nil error in case of success and the zero value for the type and a non-nil error on failure.

func CopySkipUnsupported

func CopySkipUnsupported[T any](src T) (T, error)

CopySkipUnsupported creates a deep copy of src. It returns the copy and a nil errorin case of success and the zero value for the type and a non-nil error on failure. Unsupported types are skipped (the copy will have the zero value for the type) instead of returning an error.

func MustCopy

func MustCopy[T any](src T) T

MustCopy creates a deep copy of src. It returns the copy on success or panics in case of any failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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