I'm trying to assemble a String from a raw pointer and a size. I'm currently using an intermediate Vec just because of its set_len function which String doesn't seem to have (ptr is a *const c_char):
let mut buf = Vec::<u8>::with_capacity(size);
ptr::copy(ptr as *const u8, buf.as_mut_ptr(), size);
buf.set_len(size);
let str = StdString::from_utf8_unchecked(buf);
but I'd like to do:
let mut str = StdString::with_capacity(size);
ptr::copy(ptr as *const u8, str.as_mut_ptr(), size);
str.set_len(size);