Contents

swift-atoms/swift-property

Use this package to give a type namespaced operations such as stack.push.back(1) or container.forEach.consuming { … }: declare an empty tag type per namespace, return a Property::Property<Tag, Base> (or one of its nested accessors) from a computed property, and write the op

Laws

  • Tag, Element, n and m are phantom: they hold no storage and only select which extensions apply. Two accessors over the same Base with different tags are the same value under different namespaces. Through Carrier, underlying is base and Property::Property.Domain is Tag.
  • Property::Property and Property::Property.Typed hold base by value. A mutation reaches the host only if the host's _modify accessor writes property.base back after the yield. The tests' accessors first replace the host with an empty value so the copy stays uniquely referenced.
  • Property::Property.Borrow and Property::Property.Inout hold a reference to the host and cannot outlive the access that created them. Writes through Property::Property.Inout land in the host directly. The unsafe initializer from a borrowing base is for reads only: writing through it mutates storage the caller only borrowed.
  • Property::Property.Consume hands its value over once. Before consume(), borrow() and restore() return the base, and repeated calls return the same base. The first consume() returns the base. After it, consume(), borrow() and restore() return nil, and isConsumed stays true. A host's _modify writes the value back only when restore() returns a value, so a consuming operation leaves the host empty and a borrowing one leaves it as it was.
  • Every Property::Property.Consume built with init(state:) from the same Property::Property.Consume.State shares that state, so a consumption through one is visible through all of them. Outside Embedded, each read or transition happens under a Mutex, so no reader ever sees isConsumed true while borrow() still returns a base. Under Embedded the state has no lock.

Package Metadata

Repository: swift-atoms/swift-property

Default branch: main

README: README.md