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

implement AtomicStorage for Optionals of RawRepresentable types #42

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

glessard
Copy link
Contributor

An example I wrote a while back needs atomics both for a RawRepresentable type and its Optional. This particular combination of functionality was missing from the package.

This PR defines an implementation of AtomicStorage for this case:

public struct AtomicOptionalRawRepresentableStorage<Wrapped>: AtomicStorage
  where Wrapped: RawRepresentable,
        Wrapped.RawValue: AtomicOptionalWrappable {
  // ...
}

A RawRepresentable type can semi-automatically conform to AtomicOptionalWrappable by declaring
(via typealias) that its AtomicOptionalRepresentation is AtomicOptionalRawRepresentableStorage<Self>.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've verified that my change does not break any existing tests.
  • I've updated the documentation if necessary.

@glessard glessard requested a review from lorentey September 18, 2021 00:03
@glessard
Copy link
Contributor Author

I don't have complete tests yet, but thought I should check in for feedback anyway.

Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

Nice! 👍

We'll need to add some tests, too -- extending Basics.swift.gyb should be enough to land this, I think.

state the layout compatibility guarantee

Co-authored-by: Karoy Lorentey <klorentey@apple.com>
@lorentey lorentey added this to the 1.1.0 milestone Sep 24, 2021
@lorentey
Copy link
Member

I suspect testing will uncover an issue with the current definition of RawRepresentable.AtomicOptionalRepresentation, but let's land this on current main before tackling that.

@lorentey lorentey merged commit 9088deb into apple:main Mar 20, 2023
@glessard glessard deleted the optional-rawrepresentable-atomic branch March 20, 2023 18:57
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.

2 participants