Avatar
swift-collections の ContainersPreview にある Mut<T>: ~Copyable, ~Escapable ですが,lifetime annotation を使えばこのように stored property に持たせることができるみたいですね.(要 experimental feature Lifetimes) struct S: ~Copyable, ~Escapable { var prop: Mut<Int> @_lifetime(&x) init(_ x: inout Int) { self.prop = .init(&x) } mutating func countUp() { self.prop[] += 1 } } いつの間にか以下のページに lifetime annotation のドキュメントが作られつつあるのを知りました. https://github.com/swiftlang/swift/blob/main/docs/ReferenceGuides/LifetimeAnnotation.md 以下のコメントの続きです.(ここまでくると beginner ではないかな…と思いこっちに) https://discord.com/channels/291054398077927425/1390573543720489112/1390609284668194908