Made File.Handle a non-copyable struct in the library to adopt Swift 6.4.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension File {
|
||||
/// An open file. Wraps `SDFile`. The file is closed on deinit if it has
|
||||
/// not been closed explicitly.
|
||||
public final class Handle {
|
||||
/// An open file. Wraps `SDFile`. The file is closed when the handle goes
|
||||
/// out of scope, unless it was closed explicitly with `close()`.
|
||||
///
|
||||
/// The handle is non-copyable: it has a single owner, so it cannot be
|
||||
/// used after `close()` and no heap allocation backs it.
|
||||
public struct Handle: ~Copyable {
|
||||
let pointer: UnsafeMutableRawPointer
|
||||
private var isClosed = false
|
||||
|
||||
/// Opens the file at `path`.
|
||||
public init(path: String, mode: Options) throws(PlaydateError) {
|
||||
@@ -17,15 +19,16 @@ extension File {
|
||||
}
|
||||
|
||||
deinit {
|
||||
if !isClosed {
|
||||
_ = fileAPI.pointee.close.unsafelyUnwrapped(pointer)
|
||||
}
|
||||
_ = fileAPI.pointee.close.unsafelyUnwrapped(pointer)
|
||||
}
|
||||
|
||||
/// Closes the file. Further operations are invalid.
|
||||
public func close() throws(PlaydateError) {
|
||||
guard !isClosed else { return }
|
||||
isClosed = true
|
||||
/// Closes the file, consuming the handle.
|
||||
// `@export(interface)` lets `discard` compile in Embedded Swift with
|
||||
// the 6.4 release toolchain; later toolchains accept it without.
|
||||
@export(interface)
|
||||
public consuming func close() throws(PlaydateError) {
|
||||
let pointer = self.pointer
|
||||
discard self
|
||||
if fileAPI.pointee.close.unsafelyUnwrapped(pointer) != 0 { throw lastFileError() }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user