Debian Codegraph @

generic/api.go

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