Following the example code on the README:
type MyStruct struct {
Int64 int64
StringPtr *string
}
func (this *MyStruct) Equal(that *MyStruct) bool {
return deriveEqual(this, that)
}
// alternatively
func (this MyStruct) Equal(that MyStruct) bool {
return deriveEqual(&this, &that)
}
Results in:
func deriveEqual(this, that *MyStruct) bool {
return (this == nil && that == nil) ||
this != nil && that != nil &&
this.Int64 == that.Int64 &&
((this.StringPtr == nil && that.StringPtr == nil) || (this.StringPtr != nil && that.StringPtr != nil && *(this.StringPtr) == *(that.StringPtr)))
}
However, when this uses a non-pointer receiver:
func (this MyStruct) Equal(that MyStruct) bool {
return deriveEqual(this, that)
}
This generates:
func deriveEqual(this, that MyStruct) bool {
return ((&this == nil && &that == nil) || (&this != nil && &that != nil && (*(&this)).Equal(*(&that))))
}
Which doesn't perform the same checks?
Following the example code on the README:
Results in:
However, when this uses a non-pointer receiver:
This generates:
Which doesn't perform the same checks?