You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
e.g. unsafe { CompactString::with_capacity(1234).as_mut_bytes() } returns a slice of length 1234. This is questionable (even if it hasn't been declared officially UB yet) and IMO should return a &mut [MaybeUninit<u8>], e.g. by the precedent set by Vec::spare_capacity_mut.
Also, the documentation is not very clear that the returned slice includes those uninitialized bytes (i.e. those past len up to capacity), and doesn't disclose that there may be uninitialized bytes hiding in the result. It's especially confusing since the documentation lists the methods in order as as_str(), as_mut_str(), as_bytes(), and as_mut_bytes() - but only the last one reveals the uninitialized part.
The text was updated successfully, but these errors were encountered:
Great callout! The as_mut_bytes(...) API definitely needs to be improved (or removed?), from a types and documentation perspective. I'll try and get to this before we release v0.8.0 since it would be a public API change.
Not sure if the API for as_mut_bytes(...) should only returns the bytes up-to len, or if we keep the current behavior and just document it. I'll need to think on this/look at what String and others do.
e.g.
unsafe { CompactString::with_capacity(1234).as_mut_bytes() }
returns a slice of length 1234. This is questionable (even if it hasn't been declared officially UB yet) and IMO should return a&mut [MaybeUninit<u8>]
, e.g. by the precedent set byVec::spare_capacity_mut
.Also, the documentation is not very clear that the returned slice includes those uninitialized bytes (i.e. those past
len
up tocapacity
), and doesn't disclose that there may be uninitialized bytes hiding in the result. It's especially confusing since the documentation lists the methods in order asas_str()
,as_mut_str()
,as_bytes()
, andas_mut_bytes()
- but only the last one reveals the uninitialized part.The text was updated successfully, but these errors were encountered: