Skip to content
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

Make Resilient conditionally conform to Equatable and Hashable #56

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

calda
Copy link
Member

@calda calda commented Sep 27, 2024

This PR makes Resilient conditionally conform to Equatable and Hashable when Value conforms to Equatable or Hashable.

This lets us simplify code like:

struct RemoteFileUpload {
  let value: String?
  let fileType: String?
  let fileName: String?
  @Resilient var url: URL?
  let content: Data?
}

/// Manual `Equatable` conformance is required when using `@Resilient`.
extension RemoteFileUpload: Equatable {
  static func ==(lhs: RemoteFileUpload, rhs: RemoteFileUpload) -> Bool {
    lhs.value == rhs.value
      && lhs.fileType == rhs.fileType
      && lhs.fileName == rhs.fileName
      && lhs.url == rhs.url
      && lhs.content == rhs.content
  }
}

to just:

struct RemoteFileUpload: Equatable {
  let value: String?
  let fileType: String?
  let fileName: String?
  @Resilient var url: URL?
  let content: Data?
}

Copy link
Collaborator

@dfed dfed left a comment

Choose a reason for hiding this comment

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

smart. love this. Might make sense to do the same thing with Sendable, but I'd need to think through that one more.

@calda calda merged commit 1fe2eef into airbnb:master Sep 27, 2024
3 checks passed
@GeorgeLyon
Copy link
Collaborator

👋 You may want to update this documentation as to why we didn't do this in the first place :)
https://github.com/airbnb/ResilientDecoding#why-doesnt-resilient-conform-to-hashable-or-equatable-when-its-value-does

@calda
Copy link
Member Author

calda commented Sep 28, 2024

Good idea, here you go: #56

calda added a commit that referenced this pull request Sep 28, 2024
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.

4 participants