-
Notifications
You must be signed in to change notification settings - Fork 78
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.
borrowing
andconsuming
become contextual keywords inside parameter type declarations. They can appear in the same places as theinout
modifier, and are mutually exclusive with each other and withinout
. In afunc
,subscript
, orinit
declaration, they appear as follows:func foo(_: borrowing Foo) func foo(_: consuming Foo) func foo(_: inout Foo)
Methods can also use the
consuming
orborrowing
modifier to indicate respectively that they consume ownership of theirself
parameter or that they borrow it. These modifiers are mutually exclusive with each other and with the existingmutating
modifier: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