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 - Rust Tutorial
From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
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
-
-
-
-
-
-
-
-
(Locked)
Introduction to function basics1m 11s
-
(Locked)
Demo: Simple unit functions1m 46s
-
(Locked)
Demo: Return values5m 50s
-
(Locked)
Demo: Using arguments3m 36s
-
(Locked)
Demo: The borrowing concept10m 9s
-
(Locked)
Demo: Using panic to stop a program4m
-
(Locked)
Demo: Basic error handling with match6m 55s
-
(Locked)
Summary of function basics1m 23s
-
(Locked)
-
-
-
-
-
-
-