-
Notifications
You must be signed in to change notification settings - Fork 10
Description
One issue with implementing nodes in gantz at present is that input and output types to a node must be "solid" types. As a result, implementing something even as simple as Add can be quite painful, as there would need to be an AddF32, AddF64, AddI32, etc just to be able to support all the possible kinds of addition. Even then, nodes would be missing for all custom implementations of Add.
Ideally, there would be some way of allowing nodes to take "generic" input and output types, as long as those types satisfy some trait bound that describes the node's behaviour. Unfortunately this isn't as simple as it sounds.
Downcasting to Trait implementations (trait objects)
Currently rust only provides the ability to downcast from types implementing Any to other solid types, but not to trait implementations. This is an issue for the node as we want to avoid knowing exactly what the type is - we just want to know that it can behave in the way that we expect (addition in our case). Things get more complicated when we take into account the fact that not only the individual type matters, but the other input and output types also matter. E.g. a single type can have multiple Add implementations based on the right-hand side argument, and each of these implementations may imply different Output types as well. Thus, simple "trait downcasting" cannot be the whole answer.
More likely, we can use some combination of some higher-level custom trait and a blanket implementation for all types implementing the trait we actually care about (perhaps with some wrapper type to help).