pub struct SharedPtr<T> { /* private fields */ }Expand description
A smart pointer that automatically manages the reference count of an Objective-C object.
C++ equivalent: NS::SharedPtr<_Class>
§Ownership
SharedPtr owns a reference to the underlying Objective-C object. When the SharedPtr
is dropped, it will release the reference. When cloned, it will retain a new reference.
Implementations§
Sourcepub fn null() -> Option<Self>
pub fn null() -> Option<Self>
Create a null SharedPtr.
Note: Unlike C++, Rust’s NonNull cannot be null, so this returns an Option.
For null representation, use Option<SharedPtr<T>>.
C++ equivalent: SharedPtr()
Sourcepub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self>
pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self>
Create a SharedPtr from a raw pointer, taking ownership.
§Safety
- The pointer must be a valid Objective-C object.
- The caller must ensure the object has a retain count of at least 1.
- Ownership is transferred to the SharedPtr (no additional retain).
C++ equivalent: Used internally by TransferPtr
Sourcepub fn get(&self) -> *mut c_void
pub fn get(&self) -> *mut c_void
Get the raw pointer to the Objective-C object.
C++ equivalent: _Class* get() const
Sourcepub fn as_ptr(&self) -> *const c_void
pub fn as_ptr(&self) -> *const c_void
Get the raw pointer (const version for API compatibility).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset this SharedPtr to null, releasing the reference.
C++ equivalent: void reset()