Borrowing

In Rust, it can be useful to use a value's content without taking ownership of the value. To do this, you can take a reference to a value, borrowing it, instead of taking ownership of the value. Here is an example of a signature of a function which gets the length of a.

Example
Here, the string is never owned by the function, but instead the function owns a reference to the string.

Returning references
Because references only point to data instead of owning it, you cannot return a reference to local data owned by the current function, because that data is dropped and no longer accessible once the function has exited. This code doesn't compile:

is destroyed at the end of the function, so a reference to it would be invalid, but Rust is able to prevent this. The solution to this is to return an owned  instead of a reference.

However, you can return references from functions if they are derived from references in the parameters. For example:

This code is valid because the returned reference borrows a string which is not owned by the current function. Rust enforces this system via the use of lifetimes. The above code is equivalent to:

Now you can see why the initial code didn't work; there was no lifetime to assign to the returned  type.