Function core::str::from_raw_parts_mut [] [src]

unsafe fn from_raw_parts_mut<'a>(p: *mut u8, len: usize) -> &'a mut str

Forms a str from a pointer and a length.

The len argument is the number of bytes in the string.

Safety

This function is unsafe as there is no guarantee that the given pointer is valid for len bytes, nor whether the lifetime inferred is a suitable lifetime for the returned str.

The data must be valid UTF-8

p must be non-null, even for zero-length str.

Caveat

The lifetime for the returned str is inferred from its usage. To prevent accidental misuse, it's suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the str, or by explicit annotation. Performs the same functionality as from_raw_parts, except that a mutable str is returned.