@@ -127,32 +127,6 @@ extension Option where Value: CustomStringConvertible {
127127 }
128128}
129129
130- // MARK: Convenience initializers when Value: RawRepresentable and Value.RawValue == String
131-
132- extension Option where Value: RawRepresentable , Value. RawValue == String {
133- /// Initializes a new option when not used as a `@propertyWrapper`
134- ///
135- /// - Parameters
136- /// - key: Explicit key value
137- /// - wrappedValue: The underlying value
138- public init ( key: some CustomStringConvertible , value: Value ) {
139- keyOverride = key. description
140- wrappedValue = value
141- unwrap = { [ $0. rawValue] }
142- }
143-
144- /// Initializes a new option when used as a `@propertyWrapper`
145- ///
146- /// - Parameters
147- /// - wrappedValue: The underlying value
148- /// - _ key: Optional explicit key value
149- public init ( wrappedValue: Value , _ key: String ? = nil ) {
150- keyOverride = key
151- self . wrappedValue = wrappedValue
152- unwrap = { [ $0. rawValue] }
153- }
154- }
155-
156130// MARK: Convenience initializers when Value == Optional<Wrapped>
157131
158132extension Option {
@@ -181,32 +155,6 @@ extension Option {
181155 self . wrappedValue = wrappedValue
182156 unwrap = { [ $0? . description] . compactMap { $0 } }
183157 }
184-
185- /// Initializes a new option when not used as a `@propertyWrapper`
186- ///
187- /// - Parameters
188- /// - key: Explicit key value
189- /// - wrappedValue: The underlying value
190- public init < Wrapped> ( key: some CustomStringConvertible , value: Wrapped ? ) where Wrapped: RawRepresentable ,
191- Wrapped. RawValue == String , Value == Wrapped ?
192- {
193- keyOverride = key. description
194- wrappedValue = value
195- unwrap = { [ $0? . rawValue] . compactMap { $0 } }
196- }
197-
198- /// Initializes a new option when used as a `@propertyWrapper`
199- ///
200- /// - Parameters
201- /// - wrappedValue: The underlying value
202- /// - _ key: Optional explicit key value
203- public init < Wrapped> ( wrappedValue: Wrapped ? , _ key: String ? = nil ) where Wrapped: RawRepresentable ,
204- Wrapped. RawValue == String , Value == Wrapped ?
205- {
206- keyOverride = key
207- self . wrappedValue = wrappedValue
208- unwrap = { [ $0? . rawValue] . compactMap { $0 } }
209- }
210158}
211159
212160// MARK: Convenience initializers when Value == Sequence<E>
@@ -237,32 +185,6 @@ extension Option {
237185 self . wrappedValue = wrappedValue
238186 unwrap = { $0. map ( \E . description) }
239187 }
240-
241- /// Initializes a new option when not used as a `@propertyWrapper`
242- ///
243- /// - Parameters
244- /// - key: Explicit key value
245- /// - wrappedValue: The underlying value
246- public init < E> ( key: some CustomStringConvertible , values: Value ) where Value: Sequence , Value. Element == E ,
247- E: RawRepresentable , E. RawValue == String
248- {
249- keyOverride = key. description
250- wrappedValue = values
251- unwrap = { $0. map ( \E . rawValue) }
252- }
253-
254- /// Initializes a new option when used as a `@propertyWrapper`
255- ///
256- /// - Parameters
257- /// - wrappedValue: The underlying value
258- /// - _ key: Optional explicit key value
259- public init < E> ( wrappedValue: Value , _ key: String ? = nil ) where Value: Sequence , Value. Element == E ,
260- E: RawRepresentable , E. RawValue == String
261- {
262- keyOverride = key
263- self . wrappedValue = wrappedValue
264- unwrap = { $0. map ( \E . rawValue) }
265- }
266188}
267189
268190// MARK: ExpressibleBy...Literal conformances
@@ -305,6 +227,20 @@ extension Option: ExpressibleByStringInterpolation where Value: StringProtocol {
305227 }
306228}
307229
230+ extension Option : Decodable where Value: Decodable & CustomStringConvertible {
231+ public init ( from decoder: Decoder ) throws {
232+ let container = try decoder. singleValueContainer ( )
233+ self . init ( wrappedValue: try container. decode ( Value . self) )
234+ }
235+ }
236+
237+ extension Option : Encodable where Value: Encodable {
238+ public func encode( to encoder: Encoder ) throws {
239+ var container = encoder. singleValueContainer ( )
240+ try container. encode ( wrappedValue)
241+ }
242+ }
243+
308244// MARK: Internal Types
309245
310246/*
0 commit comments