by kbolino · 2y ago · 0 comments
This wouldn't be such a problem, since of course you can just "choose" to not use pointer- or interface-typed fields in "your" structs, but as soon as serialization, databases, or other people's APIs are involved, you don't have that "choice" anymore.
In the same vein, being unable to write e.g. &true or &"foo" is annoying too. If I can write &struct{...} why can't I write &true?
package ptr
func To[T any](v T) *T {
return &v
}On the plus side, at least the AWS SDK provides `aws.String()` and friends.
Unfortunately, there's no generic type constraint for "is an interface" or even "is nilable" so you can't use generics to solve nil-safety issues in general.
&([]bool{true}[0])
But at least it allows me to write it without declaring a variable first.