Skip to content

Commit

Permalink
lifetime exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaopmorais committed Feb 20, 2024
1 parent 05b9a11 commit 340491d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions exercises/16_lifetimes/lifetimes1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions exercises/16_lifetimes/lifetimes2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -22,6 +21,7 @@ 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);

}
8 changes: 3 additions & 5 deletions exercises/16_lifetimes/lifetimes3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
// 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() {
Expand Down

0 comments on commit 340491d

Please sign in to comment.