OptionalRustObject
open class OptionalRustObject : Destroyable
Base class that wraps an optional OpaquePointer
representing a pointer to a Rust object.
This class should be used to wrap Rust pointer that point to consuming structs, that is, calling a function
for that Rust pointer, will cause Rust to destroy the pointer, leaving the Swift pointer dangling.
These classes are responsible for ensuring that their raw OpaquePointer
are nil
led after calling a consuming
FFI function.
This class provides cleanup functions on deinit, ensuring that all classes
that inherit from it will have their OpaquePointer
destroyed when the Swift wrapper is destroyed.
If a class does not override cleanup
then a fatalError
is thrown.
The optional pointer is managed here such that is the pointer is nil, then the cleanup function is not called
ensuring that we do not double free the pointer on exit.
-
Undocumented
Declaration
Swift
public init(raw: UnsafeMutableRawPointer)
-
Undocumented
Declaration
Swift
public init(raw: OpaquePointer?)
-
Undocumented
Declaration
Swift
public func getRaw() -> OpaquePointer?
-
Provides a non-optional
OpaquePointer
if one exists for this class.Throws
Pointer.pointerConsumed
if the raw pointer wrapped by this class is nilDeclaration
Swift
public func validPointer() throws -> OpaquePointer
Return Value
the raw
OpaquePointer
wrapped by this class. -
Undocumented
Declaration
Swift
open func cleanup(pointer: OpaquePointer)