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 asc, andC(u).underlyingisu. init(_:validate:)runsvalidateonce, on the borrowed underlying value, before the carrier exists. Ifvalidatethrows, no carrier is constructed and that error propagates unchanged.- A conformer whose
Carrier.Protocol.UnderlyingisSelfgets defaults in whichunderlyingyieldsselfandinit(_:)is the identity. The standard-library conformances in this package are all such self-carriers withDomainleft atNever. - When
Carrier.Protocol.Underlyingis aFixedWidthInteger, the bitwise and shift operators compute on the underlying values and rewrap the result throughinit(:), so they never run a validation thatinit(:validate:)would have run. They are disfavored overloads: an operator declared on the concrete type always wins. Shifts keepFixedWidthInteger's smart-shift behaviour.isZeroandisNonZerocompare the underlying value with0.
Package Metadata
Repository: swift-atoms/swift-carrier
Default branch: main
README: README.md