APIs
from: Create astringfrom a string literal. e.g.:let s = String::from("hello");push: appends a literal to a string. e.g.:s.push_str(", world!");.as_bytes: ConvertsStringinto an array of bytes.slice: With Rust’s..range syntax, if you want to start at index 0, you can drop the value before the two periods. In other words, these are equal:let hello = &s[0..5];andlet hello = &s[..5]. By the same token, if your slice includes the last byte of theString, you can drop the trailing number. You can also drop both values to take a slice of the entire string.Note: String slice range indices must occur at valid UTF-8 character boundaries. If you attempt to create a string slice in the middle of a multibyte character, your program will exit with an error. For the purposes of introducing string slices, we are assuming ASCII only in this section; a more thorough discussion of UTF-8 handling is in the “Storing UTF-8 Encoded Text with Strings” section of Chapter 8.