I have the following generic interface
type Worker[input any, output any] interface {
Process(input) output
}
I'm trying to implement the interface with the following
type IntWorker[i int, o int] struct{}
func (w *IntWorker[i, o]) Process(input i) o {
fmt.Println("running i")
return 1
}
When I try to use this I get the following error
mgr := internal.NewWorkManager()
iwkr := &IntWorker[int, int]{}
mgr.RegisterWorker(iwkr)
cannot use iwkr (variable of type *IntWorker[int, int]) as internal.Worker[any, any] value in argument to : *IntWorker[int, int] does not implement internal.Worker[any, any] (wrong type for method Process)
have Process(input int) int
want Process(any) any
Note the last segment, it says want any but have int. I'm not sure how to fix this since I was under the impression you can pass anything to any
The variable is passed to this function:
func (m *WorkManager) RegisterWorker(f Worker[any, any]) uuid.UUID