Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Features Rc::clone_raw() and Arc::clone_raw() #79952

Closed
wants to merge 13 commits into from
11 changes: 11 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,17 @@ impl<T: ?Sized> Rc<T> {

unsafe { Self::from_ptr(rc_ptr) }
}

/// Obtains a new reference two a raw [`Rc`] pointer, without taking ownership.
pub unsafe fn clone_raw(ptr: *const T) -> Self {
let result = unsafe {
Rc::from_raw(ptr)
};

std::mem::forget(result.clone())

result
}

/// Creates a new [`Weak`] pointer to this allocation.
///
Expand Down