Using property wrappers with Codable
gives another reason to want something like this: the decoder implementation has no access to the "shared info" values. We can't give Clamped
a Decodable
conformance (because where would the range value come from?), so as soon as we use @Clamped
on a member of a Decodable
type we're forced to implement a custom init(from:)
for that type.
(I have another use case in mind: converting an optional codable member to non-optional by giving a default fallback value, to deal with json that skips keys with default values. I'm not sure if a solution that works for @Clamped
would already make this possible though, because of complications to do with the autosynthesized decoder's handling of missing keys. Not having access to the default value in the property-wrapper's Decodable
implementation is certainly one of the things in the way, however.)