deepcopy

package
v0.0.0-...-e3f2fdf Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package deepcopy contains the implementation of the deepcopy plugin, which generates the deriveDeepCopy function.

The deriveDeepCopy function is a maintainable and fast way to implement fast copy functions.

When goderive walks over your code it is looking for a function that:

  • was not implemented (or was previously derived) and
  • has a predefined prefix.

In the following code the deriveDeepCopy function will be found, because it was not implemented and it has a prefix deriveDeepCopy. This prefix is configurable.

package main

import "sort"

type MyStruct struct {
	Int64     int64
	StringPtr *string
}

func (m *MyStruct) Clone() *MyStruct {
	if m == nil {
		return nil
	}
	n := &MyStruct{}
	deriveDeepCopy(n, m)
	return n
}

The initial type that is passed into deriveDeepCopy needs to have a reference type:

  • pointer
  • slice
  • map

, otherwise we are not able to modify the input parameter and then what are you really copying, but as we go deeper we support most types.

Supported types:

  • basic types
  • named structs
  • slices
  • maps
  • pointers to these types
  • private fields of structs in external packages (using reflect and unsafe)
  • and many more

Unsupported types:

  • chan
  • interface
  • function
  • unnamed structs, which are not comparable with the == operator

Example output can be found here: https://github.com/awalterschulze/goderive/tree/master/example/plugin/deepcopy

This plugin has been tested thoroughly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New is a constructor for the deepcopy code generator. This generator should be reconstructed for each package.

func NewPlugin

func NewPlugin() derive.Plugin

NewPlugin creates a new deepcopy plugin. This function returns the plugin name, default prefix and a constructor for the deepcopy code generator.

Types

This section is empty.

Jump to

Keyboard shortcuts

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