Trait rscontainer::internals::ISharedPointer [−][src]
pub unsafe trait ISharedPointer: Sized + Clone { unsafe fn into_ptr(self) -> NonNull<()>; unsafe fn from_ptr(ptr: NonNull<()>) -> Self; fn ptr_eq(&self, other: &Self) -> bool; unsafe fn clone_from_ptr(ptr: NonNull<()>) -> Self { ... } unsafe fn drop_from_ptr(ptr: NonNull<()>) { ... } }
Expand description
A smart pointer that can be used to store a shared instance.
Safety
This trait may only be implemented on reference counted pointers, such as
Rc
and Arc
. It may not be implemented on Box
, because it could lead
to multiple boxes pointing to the same location.
Required methods
Transforms the smart pointer into a raw pointer.
Safety
After calling this method, dropping of the smart pointer should be manually handled.
Re-inits the smart pointer from a type erased raw pointer.
Safety
ptr
should be created by the into_ptr()
method of the
same impl block. This ensures that ptr
has the same type as Self
.
Apart from dropping, the returned smart pointer should always be cloned before it’s used, because this method does not increase the ref count.
It is preferred to use the clone_from_ptr
method instead.
Provided methods
unsafe fn clone_from_ptr(ptr: NonNull<()>) -> Self
[src]
unsafe fn clone_from_ptr(ptr: NonNull<()>) -> Self
[src]Creates a clone of the smart pointer from a raw pointer.
This increases the reference count of the smart pointer.
Safety
ptr
should be created by the into_ptr()
method of the
same impl block. This ensures that ptr
has the same type as Self
.
unsafe fn drop_from_ptr(ptr: NonNull<()>)
[src]
unsafe fn drop_from_ptr(ptr: NonNull<()>)
[src]Decreases the reference count when the service container is dropped.
Safety
ptr
should be created by the into_ptr()
method of the
same impl block. This ensures that ptr
has the same type as Self
.
After this method ptr
points to possibly freed memory, so it should
not be used anymore.