Skip to content

Commit 867848f

Browse files
committed
Add conditional conformance to Decodable and Encodable to Option
bugfix/remove-rawrep-string-init-for-option
1 parent b527467 commit 867848f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/ArgumentEncoding/Option.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ extension Option: ExpressibleByStringInterpolation where Value: StringProtocol {
227227
}
228228
}
229229

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+
230244
// MARK: Internal Types
231245

232246
/*

0 commit comments

Comments
 (0)