alloc::str::from_utf8_mut - Rust
Description: API documentation for the Rust `from_utf8_mut` fn in crate `alloc`.
Keywords: rust, rustlang, rust-lang, from_utf8_mut

# 1.20.0[−][src]Function alloc::str::from_utf8_mut

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

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

# Examples

Basic usage:

    use std::str;

    // "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 = str::from_utf8_mut(&mut hellorust).unwrap();

    assert_eq!("Hello, Rust!", outstr);

Incorrect bytes:

    use std::str;

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

    assert!(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.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)