A string slice lets us work with some or all of a string without creating another owned String. The type of a string slice is &str in source
let message = String::from("Server started");
let first_word = &message[0..6];Here, the first_word doesn’t own another copy of “Server”, it refers to the first six bytes inside message
We can borrow the entire string as a slice too:
let message = String::from("Server started");
let whole: &str = &message[..];
let part: &str = &message[0..6];A string literal is also a &str:
let message: &str = "Server started";