Struct objc2::rc::Weak

source ·
pub struct Weak<T: ?Sized> { /* private fields */ }
Expand description

A weak pointer to an Objective-C reference counted object.

The object is allowed to be deallocated while the weak pointer is alive, though the backing allocation for the object can only be released once all weak pointers are gone.

Useful for breaking reference cycles and safely checking whether an object has been deallocated.

§Comparison to std types

This is the Objective-C equivalent of sync::Weak from the standard library, and hence is only usable on types where Retained<T> acts like sync::Arc, a.k.a. on non-mutable types.

Implementations§

source§

impl<T: Message> Weak<T>

source

pub fn new(obj: &T) -> Self
where T: IsRetainable,

Construct a new weak pointer that references the given object.

source

pub fn from_id(obj: &Retained<T>) -> Self
where T: IsIdCloneable,

Construct a new weak pointer that references the given Retained.

Soft-deprecated alias of Weak::from_retained.

source

pub fn from_retained(obj: &Retained<T>) -> Self
where T: IsIdCloneable,

Construct a new weak pointer that references the given Retained.

You should prefer Weak::new whenever the object is retainable.

source

pub fn load(&self) -> Option<Retained<T>>

Load the object into an Retained if it still exists.

Returns None if the object has been deallocated, or the Weak was created with Default::default.

Trait Implementations§

source§

impl<T: Message + IsRetainable> Clone for Weak<T>

source§

fn clone(&self) -> Self

Make a clone of the weak pointer that points to the same object.

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: ?Sized> Debug for Weak<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Message + IsRetainable> Default for Weak<T>

source§

fn default() -> Self

Constructs a new weak pointer that doesn’t reference any object.

Calling Self::load on the return value always gives None.

source§

impl<T: ?Sized> Drop for Weak<T>

source§

fn drop(&mut self)

Destroys the weak pointer.

source§

impl<T: Message + IsIdCloneable> From<&Retained<T>> for Weak<T>

source§

fn from(obj: &Retained<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Message + IsRetainable> From<&T> for Weak<T>

source§

fn from(obj: &T) -> Self

Converts to this type from the input type.
source§

impl<T: Message + IsIdCloneable> From<Retained<T>> for Weak<T>

source§

fn from(obj: Retained<T>) -> Self

Converts to this type from the input type.
source§

impl<T: ?Sized + RefUnwindSafe + IsIdCloneable> RefUnwindSafe for Weak<T>

source§

impl<T: ?Sized + Sync + Send + IsIdCloneable> Send for Weak<T>

source§

impl<T: ?Sized + Sync + Send + IsIdCloneable> Sync for Weak<T>

source§

impl<T: ?Sized> Unpin for Weak<T>

source§

impl<T: ?Sized + RefUnwindSafe + IsIdCloneable> UnwindSafe for Weak<T>

Auto Trait Implementations§

§

impl<T> Freeze for Weak<T>
where T: ?Sized,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,