Contents

swift-atoms/swift-carrier

Use this package when you write code that should accept any value wrapping an underlying representation, generically over whether that wrapper or its underlying value is copyable or escapable: constrain on Carrier.Protocol (for example some Carrier.Protocol<Int>) and read `un

Laws

  • Round trip: for every conformer C, C(c.underlying) is the same value as c, and C(u).underlying is u.
  • init(_:validate:) runs validate once, on the borrowed underlying value, before the carrier exists. If validate throws, no carrier is constructed and that error propagates unchanged.
  • A conformer whose Carrier.Protocol.Underlying is Self gets defaults in which underlying yields self and init(_:) is the identity. The standard-library conformances in this package are all such self-carriers with Domain left at Never.
  • When Carrier.Protocol.Underlying is a FixedWidthInteger, the bitwise and shift operators compute on the underlying values and rewrap the result through init(:), so they never run a validation that init(:validate:) would have run. They are disfavored overloads: an operator declared on the concrete type always wins. Shifts keep FixedWidthInteger's smart-shift behaviour. isZero and isNonZero compare the underlying value with 0.

Package Metadata

Repository: swift-atoms/swift-carrier

Default branch: main

README: README.md