假设我有一个接口:
type Module interface {
Run(moduleInput x) error // x is the type of moduleInput
}
其中每个"模块"将实现Run
功能.然而,moduleInput
不是单个 struct -它应该能够接受任何 struct ,但只能接受允许的 struct ,即不是interface{}
(例如,只有moduleAInputs
和moduleBInputs
struct ).
理想情况下,每个模块的Run
函数的类型为moduleXInput
,其中X是一个示例模块.
是否可以用泛型或其他方式约束moduleInput
的类型?