[docs] unclear how to create a Box<[T]> from a pointer and a length
I wanted to create a Box<[T]> from a pointer and a length and neither the docs of slice or Box were helpful.
It wasn't hard (Box::from_raw(slice::from_raw_parts_mut(ptr, len) as *mut [u8])), but the experience could have been better.
Writing docs for this should be pretty straightforward, it's just a matter of deciding where they should go. Anyone have thoughts? Maybe at the top level for the
sliceprimitive?Corey Farwell at 2018-02-03 05:02:59
Yes, I would agree that top-level slice is a good spot.
Steve Klabnik at 2018-05-29 09:08:06
The above linked PR proposed documenting this, but in discussion the usefulness of documenting this combination was questioned and there was a question about the specific need leading the submitter to this solution. Perhaps a better solution could be suggested if the underlying need was known?
@gnzlbg do you remember in what context you used this?
Marijn Schouten at 2025-04-04 17:16:55