Refactor longest function to use lifetimes

This commit is contained in:
Rock070 2024-01-05 00:28:10 +08:00
parent b3fbab1791
commit f996183355

View File

@ -8,9 +8,7 @@
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
fn longest(x: &str, y: &str) -> &str {
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {