From b319ac6979981a8c26f3d55b673497ed07969de5 Mon Sep 17 00:00:00 2001 From: Peter Adam Korodi <52385411+kp-cat@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:44:46 +0200 Subject: [PATCH] Semantic Version 2.1.0 Update (#47) * Semantic Version 2.1.0 * merged Version files * Remove inlinable to avoid compile errors --- Sources/Version/Version.swift | 29 +++++++++++++++++++++++------ Sources/Version/version.txt | 3 ++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Sources/Version/Version.swift b/Sources/Version/Version.swift index f5d81a8..9a89daf 100644 --- a/Sources/Version/Version.swift +++ b/Sources/Version/Version.swift @@ -15,6 +15,7 @@ A struct representing a “semver” version, that is: a Semantic Version. - SeeAlso: https://semver.org */ + public struct Version { /// The major version. public let major: Int @@ -48,6 +49,18 @@ public struct Version { print("notice: negative components were abs’d") } } + + /** + Creates a version object. + - Note: Integers are made absolute since negative integers are not allowed, yet it is conventional Swift to take `Int` over `UInt` where possible. + - Remark: This initializer variant provided when it would be more readable than the nameless variant. + */ + public init(major: Int, minor: Int, patch: Int, prereleaseIdentifiers: [String] = [], buildMetadataIdentifiers: [String] = []) { + self.init(major, minor, patch, pre: prereleaseIdentifiers, build: buildMetadataIdentifiers) + } + + /// Represents `0.0.0` + public static let null = Version(0,0,0) } extension Version: LosslessStringConvertible { @@ -180,6 +193,10 @@ public extension Version { } } +#if swift(>=5.5) +extension Version: Sendable {} +#endif + extension Version: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(major) @@ -192,13 +209,13 @@ extension Version: Hashable { extension Version: Equatable { /// Compares the provided versions *without* comparing any build-metadata public static func == (lhs: Version, rhs: Version) -> Bool { - lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch && lhs.prereleaseIdentifiers == rhs.prereleaseIdentifiers + return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch && lhs.prereleaseIdentifiers == rhs.prereleaseIdentifiers } } extension Version: Comparable { func isEqualWithoutPrerelease(_ other: Version) -> Bool { - major == other.major && minor == other.minor && patch == other.patch + return major == other.major && minor == other.minor && patch == other.patch } /** @@ -232,10 +249,10 @@ extension Version: Comparable { let typedRhsIdentifier: Any = Int(rhsPrereleaseIdentifier) ?? rhsPrereleaseIdentifier switch (typedLhsIdentifier, typedRhsIdentifier) { - case let (int1 as Int, int2 as Int): return int1 < int2 - case let (string1 as String, string2 as String): return string1 < string2 - case (is Int, is String): return true // Int prereleases < String prereleases - case (is String, is Int): return false + case let (int1 as Int, int2 as Int): return int1 < int2 + case let (string1 as String, string2 as String): return string1 < string2 + case (is Int, is String): return true // Int prereleases < String prereleases + case (is String, is Int): return false default: fatalError("impossi-op") } diff --git a/Sources/Version/version.txt b/Sources/Version/version.txt index 74f369e..b38f57f 100644 --- a/Sources/Version/version.txt +++ b/Sources/Version/version.txt @@ -1 +1,2 @@ -https://github.com/mxcl/Version/releases/tag/2.0.1 +https://github.com/mxcl/Version/releases/tag/2.1.0 +Version+Comparable.swift merged into Version.swift.