Skip to content

Feature: Rc::clone_raw (and for Arc) #48108

Open
@Diggsey

Description

@Diggsey

When using from_raw/into_raw functions with Rc, you often want to obtain a new reference to a raw pointer, without taking ownership. At the moment you have to do this dance:

fn clone_raw<T>(ptr: *const T) -> Rc<T> {
    let result = unsafe { Rc::from_raw(ptr) };
    ::std::mem::forget(result.clone());
    result
}

This is quite error prone and makes little sense to anyone trying to read the code. It would be better if the standard library had clone_raw built in for Rc and Arc, and possibly for their weak variants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions