Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateReseter ¶
func GenerateReseter()
Types ¶
type Reseter ¶
type Reseter interface {
Reset()
}
Reseter Resets the struct to their default values. Except fields that implements the Reseter interface.
Fields/values that implements the Reseter interface will simply invoke .Reset(), instead of being set to nil/0/etc. to reduce GC.
TODO: allow tweaking this behavior with flags.
Example
package main import "github.com/andersfylling/ggi" type C struct{ Cool string } var _ ggi.Reseter = (*C)(nil) type B struct{ Okay bool } type A struct { Something int OtherThing *B AndThenThis *C C C } var _ ggi.Reseter = (*A)(nil)
Will generate the file `ggi_reseter.go` with the following contents:
func (c *C) Reset() { c.Cool = "" } func (a *A) Reset() { a.Something = 0 if a.OtherThing != nil { a.OtherThing.Okay = false } if a.AndThenThis != nil { a.AndThenThis.Reset() // detects Reseter implementation and resuses memory } a.C.Reset() }
type Stack ¶
type Stack interface { // Size is the number of elements in the stack Size() int // max 2,147,483,647 // Cap is the actual size of the stack Cap() int // Pop takes the next element off the stack Pop() interface{} // Push pushes the element onto the stack Push(x interface{}) // Peek shows you the next element to be removed (by either Pop or Push) Peek() interface{} }
Click to show internal directories.
Click to hide internal directories.