#[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> &).
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)