Non-pointer VariableGen

This commit is contained in:
Tim Hockin 2025-03-04 15:09:38 -08:00
parent 4e3d114c26
commit a758e725b8
No known key found for this signature in database
2 changed files with 8 additions and 8 deletions

View File

@ -1211,7 +1211,7 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
tn := g.discovered.typeNodes[t] tn := g.discovered.typeNodes[t]
variables := tn.typeValidations.Variables variables := tn.typeValidations.Variables
slices.SortFunc(variables, func(a, b *validators.VariableGen) int { slices.SortFunc(variables, func(a, b validators.VariableGen) int {
return cmp.Compare(a.Variable.Name, b.Variable.Name) return cmp.Compare(a.Variable.Name, b.Variable.Name)
}) })
for _, variable := range variables { for _, variable := range variables {

View File

@ -232,7 +232,7 @@ type Validations struct {
// Variables holds any variables which must be generated to perform // Variables holds any variables which must be generated to perform
// validation. Variables are not permitted in every context. // validation. Variables are not permitted in every context.
Variables []*VariableGen Variables []VariableGen
// Comments holds comments to emit (without the leanding "//"). // Comments holds comments to emit (without the leanding "//").
Comments []string Comments []string
@ -259,12 +259,12 @@ func (v *Validations) Len() int {
return len(v.Functions) + len(v.Variables) + len(v.Comments) return len(v.Functions) + len(v.Variables) + len(v.Comments)
} }
func (v *Validations) AddFunction(f FunctionGen) { func (v *Validations) AddFunction(fn FunctionGen) {
v.Functions = append(v.Functions, f) v.Functions = append(v.Functions, fn)
} }
func (v *Validations) AddVariable(variable *VariableGen) { func (v *Validations) AddVariable(vr VariableGen) {
v.Variables = append(v.Variables, variable) v.Variables = append(v.Variables, vr)
} }
func (v *Validations) AddComment(comment string) { func (v *Validations) AddComment(comment string) {
@ -391,8 +391,8 @@ func (fg FunctionGen) WithComment(comment string) FunctionGen {
} }
// Variable creates a VariableGen for a given function name and extraArgs. // Variable creates a VariableGen for a given function name and extraArgs.
func Variable(variable PrivateVar, initFunc FunctionGen) *VariableGen { func Variable(variable PrivateVar, initFunc FunctionGen) VariableGen {
return &VariableGen{ return VariableGen{
Variable: variable, Variable: variable,
InitFunc: initFunc, InitFunc: initFunc,
} }