swift-atomics icon indicating copy to clipboard operation
swift-atomics copied to clipboard

implement AtomicStorage for Optionals of RawRepresentable types

Open glessard opened this issue 4 years ago • 1 comments

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

  • [x] I've read the Contribution Guidelines
  • [x] My contributions are licensed under the Swift license.
  • [x] 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).
  • [x] I've verified that my change does not break any existing tests.
  • [x] I've updated the documentation if necessary.

glessard avatar Sep 18 '21 00:09 glessard

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

glessard avatar Sep 18 '21 00:09 glessard

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 avatar Mar 20 '23 02:03 lorentey