Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
Last active December 30, 2021 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmueller/df2f97950bc53d2e62c673b49a213101 to your computer and use it in GitHub Desktop.
Save matthewmueller/df2f97950bc53d2e62c673b49a213101 to your computer and use it in GitHub Desktop.
Experimenting with generics as a way of annotating fields
// You can edit this code!
// Click here and start typing.
package main
import (
"io"
)
func main() {
fmt.Println(Show(Query[int]{10}))
}
type Query[T any] struct{ t T }
func Show(q Query[int]) int {
return q.t
}
type Body[T any] struct{}
type Request struct {
gt Query[int]
}
func Show2(r *Request, body Body[io.Reader]) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment