#[repr(C)]pub struct SharedPtr<T>where
T: SharedPtrTarget,{ /* private fields */ }
Expand description
Binding to C++ std::shared_ptr<T>
.
Implementations§
sourcepub fn null() -> Self
pub fn null() -> Self
Makes a new SharedPtr wrapping a null pointer.
Matches the behavior of default-constructing a std::shared_ptr.
sourcepub fn new(value: T) -> Selfwhere
T: ExternType<Kind = Trivial>,
pub fn new(value: T) -> Selfwhere
T: ExternType<Kind = Trivial>,
Allocates memory on the heap and makes a SharedPtr owner for it.
sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Checks whether the SharedPtr does not own an object.
This is the opposite of std::shared_ptr<T>::operator bool.
sourcepub fn as_ref(&self) -> Option<&T>
pub fn as_ref(&self) -> Option<&T>
Returns a reference to the object owned by this SharedPtr if any, otherwise None.
sourcepub fn downgrade(self: &SharedPtr<T>) -> WeakPtr<T>where
T: WeakPtrTarget,
pub fn downgrade(self: &SharedPtr<T>) -> WeakPtr<T>where
T: WeakPtrTarget,
Constructs new WeakPtr as a non-owning reference to the object managed
by self
. If self
manages no object, the WeakPtr manages no object
too.
Matches the behavior of std::weak_ptr<T>::weak_ptr(const std::shared_ptr<T> &).