Documentation ¶
Overview ¶
Package subtract computes struct numerical difference.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sub ¶
func Sub[T any](curr, prev T) (diff T)
Sub computes the numerical difference between two structs of the same type. It returns the result in a new instance of the same type, and does not modify the arguments.
If the struct has `func (T) Sub(T) T` method, it is used; otherwise, this calls SubFields.
func SubFields ¶
func SubFields[T any](curr, prev T, diffPtr *T)
SubFields computes the numerical difference between two structs of the same type. It assigns the result to a pointer to the same type.
This function can handle these field types:
- unsigned/signed integer.
- struct (recursive).
- slice (recursive, truncated to the shorter slice).
- array (recursive).
Other fields are ignored. A field may be explicitly skipped with `subtract:"-"` tag.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.