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,nandmare phantom: they hold no storage and only select which extensions apply. Two accessors over the sameBasewith different tags are the same value under different namespaces. ThroughCarrier,underlyingisbaseandProperty::Property.DomainisTag.Property::PropertyandProperty::Property.Typedholdbaseby value. A mutation reaches the host only if the host's_modifyaccessor writesproperty.baseback after the yield. The tests' accessors first replace the host with an empty value so the copy stays uniquely referenced.Property::Property.BorrowandProperty::Property.Inouthold a reference to the host and cannot outlive the access that created them. Writes throughProperty::Property.Inoutland in the host directly. Theunsafeinitializer from aborrowingbase is for reads only: writing through it mutates storage the caller only borrowed.Property::Property.Consumehands its value over once. Beforeconsume(),borrow()andrestore()return the base, and repeated calls return the same base. The firstconsume()returns the base. After it,consume(),borrow()andrestore()returnnil, andisConsumedstaystrue. A host's_modifywrites the value back only whenrestore()returns a value, so a consuming operation leaves the host empty and a borrowing one leaves it as it was.- Every
Property::Property.Consumebuilt withinit(state:)from the sameProperty::Property.Consume.Stateshares that state, so a consumption through one is visible through all of them. Outside Embedded, each read or transition happens under aMutex, so no reader ever seesisConsumedtrue whileborrow()still returns a base. Under Embedded the state has no lock.
Package Metadata
Repository: swift-atoms/swift-property
Default branch: main
README: README.md