Skip to content

Conform LossLessStringConvertible for UUID #1303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jevonmao
Copy link
Contributor

As discussed in Swift Forums and implemented in several frameworks like Vapor, UUID meets the semantic contract of LosslessStringConvertible. This PR adds conformance of UUID to LosslessStringConvertible.

Closes #1292

Copy link
Contributor

@itingliu itingliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an accompanying API proposal since this is changing the public interface. Do you have one?

@@ -16,7 +16,7 @@ public typealias uuid_string_t = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8

/// Represents UUID strings, which can be used to uniquely identify types, interfaces, and other items.
@available(macOS 10.8, iOS 6.0, tvOS 9.0, watchOS 2.0, *)
public struct UUID : Hashable, Equatable, CustomStringConvertible, Sendable {
public struct UUID : Hashable, Equatable, CustomStringConvertible, Sendable, LosslessStringConvertible {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new conformance and the new init need to have the new availability annotation.

@jevonmao
Copy link
Contributor Author

@itingliu I added the proposal. Could you abbreviated review for this?

itingliu
itingliu previously approved these changes Jun 20, 2025
@itingliu
Copy link
Contributor

@swift-ci please test

@@ -115,4 +115,19 @@ final class UUIDTests : XCTestCase {
XCTAssertFalse(uuid2 > uuid1)
XCTAssertTrue(uuid2 == uuid1)
}

func test_UUIDLosslessStringConvertible() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we just recently switched to use swift-testing two weeks ago. Do you mind rebasing main and updating this test to swift-testing?

@itingliu itingliu dismissed their stale review June 23, 2025 18:45

I left a comment asking if we could switch to swift-testing from XCTest. Dismissing this review so my comment doesn't get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conform UUID to LosslessStringConvertible
2 participants