#[repr(transparent)]pub struct BorrowedArc<T>(*const T);
Expand description
Provides an access to the value of Arc on Context without cloning a reference.
We need this type because return a reference from Context require static lifetime, which allow the caller to store it at a global level. Once the value is destroyed that reference will be invalid. We can solve this by return a cloned Arc but most of the time the caller just want a temporary access to the value, which mean the increment and decrement of a reference is not needed so we invent this type to solve this problem.
This type work by making itself not Send and Sync, which prevent the caller from storing it at a global level.
Tuple Fields§
§0: *const T
Implementations§
Source§impl<T> BorrowedArc<T>
impl<T> BorrowedArc<T>
Sourcepub(super) const unsafe fn from_non_null(v: *const T) -> Self
pub(super) const unsafe fn from_non_null(v: *const T) -> Self
Sourcepub fn as_ptr(this: &Self) -> *const T
pub fn as_ptr(this: &Self) -> *const T
Note that this is an associated function, which means that you have to call it as
BorrowedArc::as_ptr(v)
instead of v.as_ptr()
. This is so that there is no conflict with
a method on the inner type.