I agree. Most of the discussion so far is focused on mechanics and not the problem to be solved.
Single property structs are trivial to write. Properties can easily be forwarded using @dynamicMemberLookup
. Protocol conformances can easily be forwarded using a protocol.
There are some things that are not possible today such as:
- forwarding methods that are not part of a protocol
- encapsulating the wrapped value while still forwarding protocols
- forwarding some protocols but not others (this is possibly, but only with a parallel set of forwarding protocols)
I think we need to be really clear about the use cases that are not well supported by the language today and would therefore make good motivation for a new language feature.
I dug up an old thread I had written about protocol-based forwarding. I was working on a second draft of that pitch when the Swift 3 proposal pause happened and never picked it up again. Some of the details should look different than the ones in that thread, but I still think a more general protocol-based forwarding feature is the right direction. It would be useful in many cases where newtype
alone would not. newtype
would still be possible to add as additional sugar.
This is somewhat representative of the kind of example that might make good motivation. However, I personally think there is benefit in handing identifiers using a single generic ID
type parameterized by a “scope” rather than a bunch distinct newtypes.