pub struct Id<T, O = Owned> { /* private fields */ }Expand description
A pointer type for Objective-C’s reference counted objects.
The object of an Id is retained and sent a release message when
the Id is dropped.
An Id may be either Owned or Shared, represented by the types Id
and ShareId, respectively. If owned, there are no other references to the
object and the Id can be mutably dereferenced. ShareId, however, can
only be immutably dereferenced because there may be other references to the
object, but a ShareId can be cloned to provide more references to the
object. An owned Id can be “downgraded” freely to a ShareId, but there
is no way to safely upgrade back.
Implementations§
Source§impl<T, O> Id<T, O>
impl<T, O> Id<T, O>
Sourcepub unsafe fn from_ptr(ptr: *mut T) -> Id<T, O>
pub unsafe fn from_ptr(ptr: *mut T) -> Id<T, O>
Constructs an Id from a pointer to an unretained object and
retains it. Panics if the pointer is null.
Unsafe because the pointer must be to a valid object and
the caller must ensure the ownership is correct.
Sourcepub unsafe fn from_retained_ptr(ptr: *mut T) -> Id<T, O>
pub unsafe fn from_retained_ptr(ptr: *mut T) -> Id<T, O>
Constructs an Id from a pointer to a retained object; this won’t
retain the pointer, so the caller must ensure the object has a +1
retain count. Panics if the pointer is null.
Unsafe because the pointer must be to a valid object and
the caller must ensure the ownership is correct.