From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Demo: Understanding string and str

Demo: Understanding string and str

- [Instructor] Let's see some of the differences between string and string slices in Rust. We have a string slice, which is this thing right here, which is STR. Almost always you'll see with an ampersand, which means it's almost always going to be a pointer to, a reference to some existing piece of data that is owned by someone else. The difference, one of the difference, many differences between that and string is that you cannot mute, you cannot mutate, you cannot change, you cannot modify STR or the string slice. Sometimes Rust programmers will call this a string, and this thing a string as well. But most commonly is most correct to say this is a string slice, and this is a string type. Let's start playing around with a little bit of the differences that we have here, and we are creating a string slice here. Let's take a look at what we have here. When we say, when we ask Visual Studio Code to tell us what are the types. So you'll see here that this is SDR, and that's effectively…

Contents