Documentation ¶
Overview ¶
Package compare contains the implementation of the compare plugin, which generates the deriveCompare function.
The deriveCompare function is a maintainable and fast way to implement fast Less functions.
deriveCompare(T, T) bool deriveCompare(T) func(T) bool
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 deriveCompare function will be found, because it was not implemented and it has a prefix deriveCompare. This prefix is configurable.
package main import "sort" type MyStruct struct { Int64 int64 StringPtr *string } func sortStructs(ss []*MyStruct) { sort.Slice(ss, func(i, j int) bool { return deriveCompare(ss[i], ss[j]) < 0 }) }
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/equal
This plugin has been tested thoroughly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.