> On 18 Jun 2016, at 02:25, Dave Abrahams via swift-evolution 
> <[email protected]> wrote:
> 
> on Fri Jun 17 2016, Ben Rimmington <[email protected]> wrote:
> 
>> <https://swift.org/documentation/api-design-guidelines/#type-conversion>
>> 
>>> **In initializers that perform full-width type conversions, omit the
>>> first argument label**, e.g. `Int64(someUInt32)`
>> 
>> OptionSet could add `init(_ rawValue: RawValue)` to reduce boilerplate:
>> 
>>      struct FooOptions: OptionSet {
>>          let rawValue: Int
>> 
>>          static let bar = Self(0b01)
>>          static let baz = Self(0b10)
>>      }
> 
> Great idea; please submit a proposal!
> 
> -- 
> -Dave

On second thoughts, perhaps the current design is better. OptionSet changes the 
failable initializer (inherited from RawRepresentable) into a *nonfailable* 
initializer. But if we used `init(_ rawValue: RawValue)` in OptionSet, it would 
also still have the failable initializer (which could maybe have a default 
implementation).

The original FooOptions example is missing some required boilerplate: 
`init(rawValue: Int) { self.rawValue = rawValue }`. In the future, a *macro* 
could be used to hide the RawRepresentable requirements of option sets, making 
them as easy to read/write as enum cases.

-- Ben
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to