Function generic_str::from_utf8_mut[][src]

pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut StringBase<[u8]>, Utf8Error>
Expand description

Converts a mutable slice of bytes to a mutable string slice.

Examples

Basic usage:

// "Hello, Rust!" as a mutable vector
let mut hellorust = vec![72, 101, 108, 108, 111, 44, 32, 82, 117, 115, 116, 33];

// As we know these bytes are valid, we can use `unwrap()`
let outstr = generic_str::from_utf8_mut(&mut hellorust).unwrap();

assert_eq!(outstr, <&str>::from("Hello, Rust!"));

Incorrect bytes:

// Some invalid bytes in a mutable vector
let mut invalid = vec![128, 223];

assert!(generic_str::from_utf8_mut(&mut invalid).is_err());

See the docs for Utf8Error for more details on the kinds of errors that can be returned.