Add "generic" option to the "optional" configuration for handling nullable types (#252)

This is an implementation for #251, it adds a new `"generic"` option for
the `"optional"` configuration, and a companion type
`"optional_generic_type"` which is a fully qualified type with a
placeholder `%` for the generic parameter.

Co-authored-by: Dylan R. Johnston <[email protected]>
Co-authored-by: Ben Kraft <[email protected]>
This commit is contained in:
Dylan R. Johnston
2023-05-06 10:40:03 -07:00
committed by GitHub
co-authored by Dylan R. Johnston Ben Kraft
parent 94b6a71403
commit c61d7acaa5
8 changed files with 279 additions and 12 deletions
+11
View File
@@ -262,6 +262,17 @@ func (g *generator) convertType(
// options work, recursing here isn't as connvenient.)
// Note this does []*T or [][]*T, not e.g. *[][]T. See #16.
goTyp = &goPointerType{goTyp}
} else if !typ.NonNull && g.Config.Optional == "generic" {
var genericRef string
genericRef, err = g.ref(g.Config.OptionalGenericType)
if err != nil {
return nil, err
}
goTyp = &goGenericType{
GoGenericRef: genericRef,
Elem: goTyp,
}
}
return goTyp, err
}