Joe_Groff
(Joe Groff)
137
I don't think we want to make more language decisions on top of the way fixed arrays are currently imported from C; nobody likes it (that I know of) and it desperately needs to be replaced. But a tuple would be noncopyable if any of its elements are noncopyable, once noncopyable tuples are supported, and that shouldn't need any explicit annotation. We don't have a way to directly import a C type as a noncopyable type; like Steve said, you would probably want to wrap the C type in a Swift type already to give it an API with the right borrowing/consuming behavior, a deinit if appropriate, and other functionality that integrates with the language.
It is implemented in nightly snapshot toolchains, if you want to try it out (though the declaration syntax is still @_moveOnly struct, and the disable-deinit statement is still _forget self pending a final syntax decision).
A run-once closure would be a reasonable future direction, but we don't propose that here. So there is no way to statically consume a value inside a closure yet. Nonescaping closures borrow their captures, either immutably or mutably as needed, for the duration of the call the closure is passed to, and escaping closures impose an indefinite borrow on the capture. You can still dynamically consume a captured value by wrapping it in an Optional-like enum (or eventually Optional<T> itself, once we support that), and giving the enum a mutating method that returns the value inside while resetting itself to nil.
3 Likes