equal

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 0 Imported by: 0

README

The deriveEqual function is a faster alternative to reflect.DeepEqual.

Given the following input:

package equal

type MyStruct struct {
	Int64     int64
	StringPtr *string
	Foo       *Foo
}

func (this *MyStruct) Equal(that *MyStruct) bool {
	return deriveEqual(this, that)
}

type Foo struct {
	Name  string
	other string
}

func (this *Foo) Equal(that *Foo) bool {
	return this.Name == that.Name
}

goderive will generate the following code:

// Code generated by goderive DO NOT EDIT.

package equal

// deriveEqual returns whether this and that are equal.
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))) &&
			this.Foo.Equal(that.Foo)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Foo

type Foo struct {
	Name string
	// contains filtered or unexported fields
}

func (*Foo) Equal

func (this *Foo) Equal(that *Foo) bool

type MyStruct

type MyStruct struct {
	Int64     int64
	StringPtr *string
	Foo       *Foo
}

func (*MyStruct) Equal

func (this *MyStruct) Equal(that *MyStruct) bool

Jump to

Keyboard shortcuts

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