compact_str icon indicating copy to clipboard operation
compact_str copied to clipboard

`NonNull` vs `*const` in Repr

Open overlookmotel opened this issue 1 year ago • 9 comments

This is a question more than a bug report, but just asking in case it reveals something more useful...

  • Repr's 1st field is a *const ().
  • HeapBuffer's 1st field is a ptr::NonNull<u8>.
  • StaticStr's 1st field is a ptr::NonNull<u8>.

HeapBuffer and StaticStr are both transmuted to Repr.

Is there a benefit to HeapBuffer and StaticStr using NonNull<u8> rather than *const? Does it matter that a value with a niche is transmuted to one without?

Second smaller question: Why *const () in Repr instead of *const u8? Only place which accesses this field seems to be as_slice, where it's immediately cast to *const u8. Probably it makes no difference to codegen, but I'm wondering if there's a subtlety I'm missing.

overlookmotel avatar Jan 04 '24 20:01 overlookmotel