Make mem::size_of_val and mem::align_of_val take raw pointers instead of reference
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
This would allow you to use null pointers to get the size of a value. As far as I know, these methods do not actually dereference the &T that is passed in. Here is a gist and a playground link that shows that they work just fine with null pointers, as long as you cast them to references so that it will type check.
I can't think of any reason that the pointer being passed in would actually need to be dereferenced. My understanding is that the pointer itself, along with its type, are all that are needed to give the size and alignment information.
Changing the signature to the following should be possible without breaking any backward compatibility, because &T is implicitly coerced to *const T.
fn size_of_val<T>(*const T) -> usize;
fn align_of_val<T>(*const T) -> usize;
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior described in the linked gist and Rust playground, then examine the proposed signatures for mem::size_of_val and mem::align_of_val. Research whether their operations require dereferencing the input and consider the claimed backward-compatibility impact. Done means the RFC question has a technically supported decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100