consuming on a Copyable Struct
★★★- ownership
- functions
- noncopyable
Swift 6.3.2 Report an issue
Verified quizzes have their expected answer checked by compiling and running the code with the listed Swift toolchain during the site build.
struct Point { var x = 0 }
extension Point {
consuming func bumped() -> Point {
x += 1
return self
}
}
let p = Point()
let q = p.bumped()
print(p.x)
print(q.x)
Hint
consuming on a ~Copyable value transfers ownership. What can it possibly
mean on an ordinary value-type that is Copyable?