Ian, thank you. but may be the is any workaround ? Use as a key not directly but like a derived from those interface/structure types ? Of course I may declare key like string and use switch + .(type) to mimic it.
So, a little bit more. there is a go standard package named ast. the docs about it you may find there: ast package - go/ast - Go Packages <https://pkg.go.dev/go/ast> there is an arrea where are declared a lot of types: type ArrayType struct {} type AssignStmt struct {} type BadDecl struct {} and so on and ending with type ValueSpec struct {} in fact there are a lot of them there. What do I whant is to use those types of interfaces or structures as a key to access to a value in a map. So, the question is: what type of a key for a map I must use ? Thank you. среда, 15 марта 2023 г. в 23:55:03 UTC+3, Ian Lance Taylor: > On Wed, Mar 15, 2023 at 9:17 AM alex-coder <a.gus...@gmail.com> wrote: > > > > There is a package named ast, inside there are a lot of structures like: > > ast.Comment, ast.Field, ast.Node and so on. > > And I whould like to use types of those structure as a keys. > > So, I could not figure out what type of the key I should use > > in order to store in a map something under the key ? > > I don't really understand the question. But I do know that most of > the types in the go/ast package can't be used as map keys, because > they can't be compared for equality, because they have fields of slice > type. You can't use a slice, or a struct with a field of slice type, > as a map key. > > 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/dfc41f67-5d71-4f2a-a0bf-569c5a582aedn%40googlegroups.com.