Here is my use case:
https://godoc.org/github.com/rocketlaunchr/react#UnmarshalState
That function has an argument that accepts only a struct. I use the reflect
package to iterate over the structs fields (and also to check if it
actually is a struct). The function has notapplicability for non-structs.
Currently I have to notify the user via documentation that only a struct is
allowed since the type is officially an `interface{}`. This is very crude.
If there was a way to add a type constraint for only structs, then I don't
need to use documentation, notwithstanding the use of reflect package to
iterate over the struct fields.
On Wednesday, June 24, 2020 at 10:34:40 AM UTC+10, Ian Lance Taylor wrote:
>
> On Mon, Jun 22, 2020 at 7:08 PM Pee Jai <[email protected] <javascript:>>
> wrote:
> >
> > I can't find a way to constrain for just structs. I don't want
> primitives.
>
> The design draft doesn't provide any mechanism for a type constraint
> to match any arbitrary struct type, and not any other kind of type.
>
> But it's not clear why that would be useful. The only things you can
> do with a value of an arbitrary struct type are things that you can do
> with a value of any arbitrary type.
>
> Ian
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/e86e677b-784d-47c5-b8b9-aedc37977ba5o%40googlegroups.com.