#[repr(transparent)]
pub struct SRObject<T>(_);
Expand description
Wrapper for arbitrary NSObject
types.
When returning an NSObject
, its Rust type must be wrapped in SRObject
.
The type must also be annotated with #[repr(C)]
to ensure its memory layout
is identical to its Swift counterpart’s.
use swift_rs::{swift, SRObject, Int, Bool};
#[repr(C)]
struct CustomObject {
a: Int,
b: Bool
}
swift!(fn get_custom_object() -> SRObject<CustomObject>);
let value = unsafe { get_custom_object() };
let reference: &CustomObject = value.as_ref();
corresponding Swift code
Converts this type into a shared reference of the (usually inferred) input type.
The resulting type after dereferencing.
Dereferences the value.
Executes the destructor for this type.
Read more
Serialize this value into the given Serde serializer.
Read more
Creates a swift-compatible version of the argument.
For primitives this just returns
self
,
but for
SwiftObject
types it wraps them in
SwiftRef
.
Read more
Gets a reference to the SRObject
at the root of a SwiftObject
Creates a
SwiftRef
for an object which can be used when calling a Swift function.
This function should never be called manually,
instead you should rely on the
swift!
macro to call it for you.
Read more
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From<T> for U
chooses to do.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.