lifetimes done

This commit is contained in:
David E. Perez Negron R. 2024-07-03 00:06:40 -06:00
parent ec8aefc4b9
commit 1e91ec6f03
3 changed files with 5 additions and 8 deletions

View File

@ -8,9 +8,8 @@
// 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 {

View File

@ -6,7 +6,6 @@
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
@ -22,6 +21,6 @@ fn main() {
{
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
println!("The longest string is '{}'", result);
}
println!("The longest string is '{}'", result);
}

View File

@ -5,11 +5,10 @@
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
struct Book {
author: &str,
title: &str,
struct Book<'a> {
author: &'a str,
title: &'a str,
}
fn main() {