Is there a reason that std::ptr requires T: Sized?


I’m trying to work with raw pointers to a type, T, which is not guaranteed to be Sized, but unfortunately ptr::null(), ptr::null_mut(), the is_null() method on *mut T, etc all require that T: Sized. Is there a reason for this?


I can see at least three functions that require size: copy, copy_nonoverlapping, and write_bytes.

I never used std::ptr myself so I don’t know if these functions are required or if they could be moved to a more specialized std::ptr.


I think the reason is that unsized pointers are usually (always?) “fat” pointers, with a second word that can’t be generalized. e.g. *const [T] and *const str have a length, and a trait object like *const Iterator has a vtable pointer.


Ah, right you are on both accounts! I wrote up an example which inspects the fat pointers and you get exactly what you’d expect: