Make IP/CIDR types conform to Codable (#454)

These types can benefit from swift's automatic
synthesis as the properties already conform to Codable. This will give
some flexibility for clients using these types to not have to add
extension and implement the encoding / decoding separately.
This commit is contained in:
Yibo Zhuang
2025-12-19 11:07:07 +05:30
committed by GitHub
parent 57d6e0b499
commit 8865bc95f2
5 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
/// Describes an IPv4 CIDR address block.
@frozen
public struct CIDRv4: CustomStringConvertible, Equatable, Sendable, Hashable {
public struct CIDRv4: CustomStringConvertible, Equatable, Sendable, Hashable, Codable {
/// The IP component of this CIDR address.
public let address: IPv4Address
+1 -1
View File
@@ -16,7 +16,7 @@
/// Describes an IPv4 or IPv6 CIDR address block.
@frozen
public struct CIDRv6: CustomStringConvertible, Equatable, Sendable, Hashable {
public struct CIDRv6: CustomStringConvertible, Equatable, Sendable, Hashable, Codable {
/// The IP component of this CIDR address.
public let address: IPv6Address
@@ -15,7 +15,7 @@
//===----------------------------------------------------------------------===//
@frozen
public struct IPv4Address: Sendable, Hashable, CustomStringConvertible, Equatable, Comparable {
public struct IPv4Address: Sendable, Hashable, CustomStringConvertible, Equatable, Comparable, Codable {
public let value: UInt32
@inlinable
@@ -15,7 +15,7 @@
//===----------------------------------------------------------------------===//
/// Represents an IPv6 network address conforming to RFC 5952 and RFC 4291.
public struct IPv6Address: Sendable, Hashable, CustomStringConvertible, Equatable, Comparable {
public struct IPv6Address: Sendable, Hashable, CustomStringConvertible, Equatable, Comparable, Codable {
@usableFromInline
internal let value: UInt128
+1 -1
View File
@@ -16,7 +16,7 @@
/// CIDR prefix length (e.g., `/24` for a 24-bit network mask).
@frozen
public struct Prefix: Sendable, CustomStringConvertible, Hashable {
public struct Prefix: Sendable, CustomStringConvertible, Hashable, Codable {
public let length: UInt8
/// Create a prefix (0-128). Use `ipv4(_:)` or `ipv6(_:)` for version-specific validation.