- Notifications
You must be signed in to change notification settings - Fork 83
Description
This issue is used to track the development of Swift Borrowing Features such as moveonly, consuming, and borrowing.
We give developers direct control over the ownership convention of parameters by introducing two new parameter modifiers, borrowing and consuming.
borrowingandconsumingbecome contextual keywords inside parameter type declarations. They can appear in the same places as theinoutmodifier, and are mutually exclusive with each other and withinout. In afunc,subscript, orinitdeclaration, they appear as follows:func foo(_: borrowing Foo) func foo(_: consuming Foo) func foo(_: inout Foo)
Methods can also use the
consumingorborrowingmodifier to indicate respectively that they consume ownership of theirselfparameter or that they borrow it. These modifiers are mutually exclusive with each other and with the existingmutatingmodifier:struct Foo { consuming func foo() // `consuming` self borrowing func foo() // `borrowing` self mutating func foo() // modify self with `inout` semantics }
Parameters may need to be transformed to consider such borrowing or consuming