Make mem::size_of_val and mem::align_of_val take raw pointers instead of reference #2017
Open
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;
Activity