struct Test { something string } struct Dependency {} struct Factory { build fn () ! } fn inject[T](mut serv T) ! { $for field in T.fields { if field.typ is string { serv.$(field.name) = 'Hello world!' } } } fn use_factory[F, E](factory fn (dep F) !E) Factory { return Factory{ build: fn [factory] [F]() ! { mut dep := F{} inject[F](mut dep)! dump(factory(dep)!) } } } use_factory[Dependency, Test](fn (dep Dependency) !Test { return Test{ something: 'daleks!' } }).build()!