Re: [go-nuts] Generic type alias with type conversion

2024-11-03 Thread Ian Lance Taylor
On Sun, Nov 3, 2024 at 12:41 AM hey...@gmail.com wrote: > > Not sure generic type alias is the solution, but what I'm trying to do is I > have a type like this > > type Map[K comparable, V any] struct { m map[K]V } > > and I want it to implement json.Unmarshaller to decode json objects, when K's

Fwd: Re: [go-nuts] Can not convert a generic struct type to a generic interface type in golang

2024-11-03 Thread noreply_security via golang-nuts
The Go FAQ has another, perhaps slightly more applicable, entry: https://go.dev/doc/faq#t_and_equal_interface Basically

[go-nuts] Generic type alias with type conversion

2024-11-03 Thread hey...@gmail.com
Not sure generic type alias is the solution, but what I'm trying to do is I have a type like this type Map[K comparable, V any] struct { m map[K]V } and I want it to implement json.Unmarshaller to decode json objects, when K's underlying type is string: type omap[K ~string, V any] = Map[K, V]

Re: [go-nuts] The usage of method call syntax for regular functions as a way to have "generic methods"

2024-11-03 Thread 'Axel Wagner' via golang-nuts
I'll make one more note, in an attempt to show that this problem is not easy to solve: Rust has generic methods. But it does not allow to use them in a "trait object" (it calls that "object safety"). Go's interfaces are, primarily, equivalent to Rust trait objects. The fact that Rust has not figure

Re: [go-nuts] The usage of method call syntax for regular functions as a way to have "generic methods"

2024-11-03 Thread 'Axel Wagner' via golang-nuts
On Sun, 3 Nov 2024 at 04:52, Mark Mavzon wrote: > 1. For an interface's generic methods disallow the use of "any" constraint > for type parameters. > type HasIdentity interface { > Identity[T int64 | float64](T) T // ok > // Identifoo[T any](T) T // not allowed > } > I'll note that this is