- Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Description
The docs for these are currently fairly meagre:
unsafe fn from_raw_parts(buf: *mut u8, length: usize, capacity: usize) -> StringCreates a new String from a length, capacity, and pointer.
This is unsafe because:
- We call
Vec::from_raw_partsto get aVec<u8>;- We assume that the Vec contains valid UTF-8.
unsafe fn from_raw_parts(ptr: *mut T, length: usize, capacity: usize) -> Vec
Creates a
Vec<T>directly from the raw components of another vector.This is highly unsafe, due to the number of invariants that aren't checked.
They need to be more specific about the details, e.g.:
ptrneeds to have been previously allocated viaString/Vec(at least, it's highly likely to be incorrect if it wasn't)capacityneeds to be the capacity that the pointer was allocated with.
Violating these may cause problems like corrupting the allocators internal datastructures.
Metadata
Metadata
Assignees
Labels
No labels