//===----------------------------------------------------------------------===// // // This source file is part of the Swift Collections open source project // // Copyright (c) 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// import Builtin extension Optional where Wrapped: ~Copyable { @lifetime(borrow self) @_addressableSelf public func borrow() -> Borrow? { if self == nil { return nil } let pointer = unsafe UnsafePointer( Builtin.unprotectedAddressOfBorrow(self) ) return unsafe Borrow(unsafeAddress: pointer, borrowing: self) } // #if false // Compiler bug preventing this // @lifetime(&self) // public mutating func mutate() -> Inout? { // if self == nil { // return nil // } // // let pointer = unsafe UnsafeMutablePointer( // Builtin.unprotectedAddressOf(&self) // ) // // return unsafe Inout(unsafeAddress: pointer, owner: &self) // } }