github.com/lemon-mint/libuseful@v1.3.1-0.20220724073654-ee73785d5aa0/copy.go (about)

     1  package libuseful
     2  
     3  import (
     4  	"reflect"
     5  	"unsafe"
     6  )
     7  
     8  // CopyStruct copies struct src to dst
     9  func CopyStruct(dst, src interface{}) {
    10  	dstV := reflect.ValueOf(dst)
    11  	srcV := reflect.ValueOf(src)
    12  
    13  	dstP := unsafe.Pointer(dstV.Pointer())
    14  	srcP := unsafe.Pointer(srcV.Pointer())
    15  
    16  	MemMove(dstP, srcP, dstV.Elem().Type().Size())
    17  }