pub fn construct_fake_string(ptr: *mut u8, cap: usize, len: usize) -> StringExpand description
Construct a String from a pointer, capacity and length, in a completely safe manner.
String is a Vec<u8> which is a (RawVec, usize) which is a ((Unique, usize), usize).
Rust explicitly says that structs are not guaranteed to have members in order, so instead we determine that order at runtime.
ยงSafety
This function is 100% memory-safe.
Nevetheless, remember to use std::mem::forget to deallocate the fake String, otherwise Rust
will think the pointer has been allocated by the global allocator and free it the wrong way.
As they say: Trust, but Verify.