Skip to content

Commit 15e8fd2

Browse files
committed
Split Range Codable extensions down to Encodable and Decodable extensions
1 parent dd394d9 commit 15e8fd2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

stdlib/public/core/ClosedRange.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,14 +489,16 @@ extension ClosedRange {
489489
public typealias CountableClosedRange<Bound: Strideable> = ClosedRange<Bound>
490490
where Bound.Stride : SignedInteger
491491

492-
extension ClosedRange: Codable where Bound: Codable {
492+
extension ClosedRange: Decodable where Bound: Decodable {
493493
public init(from decoder: Decoder) throws {
494494
var container = try decoder.unkeyedContainer()
495495
let lowerBound = try container.decode(Bound.self)
496496
let upperBound = try container.decode(Bound.self)
497497
self = lowerBound...upperBound
498498
}
499+
}
499500

501+
extension ClosedRange: Encodable where Bound: Encodable {
500502
public func encode(to encoder: Encoder) throws {
501503
var container = encoder.unkeyedContainer()
502504
try container.encode(self.lowerBound)

stdlib/public/core/Range.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,16 @@ extension Range: Hashable where Bound: Hashable {
405405
}
406406
}
407407

408-
extension Range: Codable where Bound: Codable {
408+
extension Range: Decodable where Bound: Decodable {
409409
public init(from decoder: Decoder) throws {
410410
var container = try decoder.unkeyedContainer()
411411
let lowerBound = try container.decode(Bound.self)
412412
let upperBound = try container.decode(Bound.self)
413413
self = lowerBound..<upperBound
414414
}
415+
}
415416

417+
extension Range: Encodable where Bound: Encodable {
416418
public func encode(to encoder: Encoder) throws {
417419
var container = encoder.unkeyedContainer()
418420
try container.encode(self.lowerBound)
@@ -462,12 +464,14 @@ extension PartialRangeUpTo: RangeExpression {
462464
}
463465
}
464466

465-
extension PartialRangeUpTo: Codable where Bound: Codable {
467+
extension PartialRangeUpTo: Decodable where Bound: Decodable {
466468
public init(from decoder: Decoder) throws {
467469
var container = try decoder.unkeyedContainer()
468470
self = try (..<container.decode(Bound.self))
469471
}
472+
}
470473

474+
extension PartialRangeUpTo: Encodable where Bound: Encodable {
471475
public func encode(to encoder: Encoder) throws {
472476
var container = encoder.unkeyedContainer()
473477
try container.encode(self.upperBound)
@@ -515,12 +519,14 @@ extension PartialRangeThrough: RangeExpression {
515519
}
516520
}
517521

518-
extension PartialRangeThrough: Codable where Bound: Codable {
522+
extension PartialRangeThrough: Decodable where Bound: Decodable {
519523
public init(from decoder: Decoder) throws {
520524
var container = try decoder.unkeyedContainer()
521525
self = try (...container.decode(Bound.self))
522526
}
527+
}
523528

529+
extension PartialRangeThrough: Encodable where Bound: Encodable {
524530
public func encode(to encoder: Encoder) throws {
525531
var container = encoder.unkeyedContainer()
526532
try container.encode(self.upperBound)
@@ -663,12 +669,14 @@ extension PartialRangeFrom: Sequence
663669
}
664670
}
665671

666-
extension PartialRangeFrom: Codable where Bound: Codable {
672+
extension PartialRangeFrom: Decodable where Bound: Decodable {
667673
public init(from decoder: Decoder) throws {
668674
var container = try decoder.unkeyedContainer()
669675
self = try container.decode(Bound.self)...
670676
}
677+
}
671678

679+
extension PartialRangeFrom: Encodable where Bound: Encodable {
672680
public func encode(to encoder: Encoder) throws {
673681
var container = encoder.unkeyedContainer()
674682
try container.encode(self.lowerBound)

0 commit comments

Comments
 (0)