#encoding.BinaryUnmarshaler as type parameter
3 messages · Page 1 of 1 (latest)
What code do you actually write... you also don't constraint it... so for instance this would/should work
func Decode[T encoding.BinaryUnmarshaler](data []byte) (T, error) {
var t T
if err := t.UnmarshalBinary(data); err != nil {
return t, err
}
return t, nil
}
actually not quite... but if you have an interface why do you need generic?