rust-lang / rust-lang/rfcs

API for retrieving Weak's base pointer

Open
#2,564 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

I'd like to use rc::Weak as keys in a HashMap, such that clones of the same Weak map to the same value, but clones of a different Weak don't.

A cleanup routine would clean up dead Weaks every once in a while, so as to not leak memory.

This is useful because the HashMap would be inside the Rc, actually it would be inside all of the Rcs for which it has a Weak key. To write it any other way would require rewriting everything I've done so far, so it'd seriously break API compatibility.

For this to work, I need to be able to get access to the Weak's base pointer. It could even return an &MaybeUninit<T> or something, idk.

In fact it would be more useful if it did &MaybeUninit<T>, if the Rc also had a similar API. I have previously asked for the ability to compare an Rc and a Weak and this would provide that too.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named in the issue. Start by reviewing the existing rc::Weak and Rc APIs and the HashMap use case described here, then determine the intended pointer-exposure and cleanup semantics. Done would require an agreed API design addressing cloned Weak identity and dead entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.