std-method
String::as_mut_str
Borrow the UTF-8 contents mutably for operations that preserve validity and the slice length. Expected stdout (not executed): CODE Common mistake: Trying to append bytes to a fixed-length mutable str view.
Formal Syntax & Structure
rust syntaxrust
fn as_mut_str(&mut self) -> &mut strWorking Example
Example Snippetrust
fn main() { let mut s = String::from("code"); s.as_mut_str().make_ascii_uppercase(); println!("{s}");}