From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Borrowing references

Borrowing references - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Borrowing references

- [Instructor] We've seen how to transfer ownership of data to and from functions using input arguments and return values but in many cases we may not actually want or need to transfer ownership of data to use it in a function. To demonstrate why, let's modify the process fuel function on line seven so that in addition to printing a message it returns the length of the propellant string. We can get the strings length by using the length function on it. And now we have two values that need to be returned that length value as well as the original propellant string to pass back ownership of it. When we need to return multiple values from a function we can package them together into a tuple. So, let's modify the functions return type and then change the return value to be a tuple containing propellant and length. Next, in the main function let's destructure the tuple that gets returned into its separate parts and then modify…

Contents