How to fix temporary value dropped while borrowed

Fix the temporary value dropped error by assigning the temporary value to a variable before borrowing it.

Store the temporary value in a variable before borrowing it to extend its lifetime. The compiler drops temporary values at the end of the statement, so you must bind the value to a named variable first to keep it alive for the borrow.

let s = String::from("hello");
let len = calculate_length(&s);

This ensures s lives long enough for calculate_length to borrow it, whereas calculate_length(&String::from("hello")) fails because the temporary string is dropped immediately after the function call.