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: Return values

Demo: Return values

- [Instructor] In a language like Rust, the return types and defining explicitly what a function is returning is very important. In this case, this function, the split_string function is returning a String. So, that condition has to be met. So whenever we're not complying with that condition, we're going to get into trouble. Now, put aside the specific knowledge of what we, you know, what types of data structures and what types we're working with here. This is an absolute truth that has to happen. At the end of the day, it doesn't matter what this function is doing. It has to return a String. And in this case, we are returning what we think is a String, but things are not quite working. Now let's walk through what we are dealing with here. We have this main function, and we have, let's see, we're calling the split_string here It's a hello,world String, and we're passing three parameters to this function. The specifics of this is not that important. The problem here is that we're…

Contents