1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright 2022 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
// Package clone provides functions to deep clone any Go data.
// It also provides a wrapper to protect a pointer from any unexpected mutation.
//
// This package is only a proxy to original go-clone package with generic support.
// To minimize the maintenace cost, there is no doc in this package.
// Please read the document in https://pkg.go.dev/github.com/huandu/go-clone instead.
package clone
import (
"reflect"
"unsafe"
"github.com/huandu/go-clone"
)
type Func = clone.Func
type Allocator = clone.Allocator
type AllocatorMethods = clone.AllocatorMethods
func Clone[T any](t T) T {
return clone.Clone(t).(T)
}
func Slowly[T any](t T) T {
return clone.Slowly(t).(T)
}
func Wrap[T any](t T) T {
return clone.Wrap(t).(T)
}
func Unwrap[T any](t T) T {
return clone.Unwrap(t).(T)
}
func Undo[T any](t T) {
clone.Undo(t)
}
func MarkAsOpaquePointer(t reflect.Type) {
clone.MarkAsOpaquePointer(t)
}
func MarkAsScalar(t reflect.Type) {
clone.MarkAsScalar(t)
}
func SetCustomFunc(t reflect.Type, fn Func) {
clone.SetCustomFunc(t, fn)
}
func FromHeap() *Allocator {
return clone.FromHeap()
}
func NewAllocator(pool unsafe.Pointer, methods *AllocatorMethods) (allocator *Allocator) {
return clone.NewAllocator(pool, methods)
}
|