Skip to content

Commit 9b2eee2

Browse files
committed
Lifetimes F
1 parent 098054a commit 9b2eee2

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

exercises/lifetimes/lifetimes1.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
99
// hint.
1010

11-
// I AM NOT DONE
12-
13-
fn longest(x: &str, y: &str) -> &str {
11+
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
1412
if x.len() > y.len() {
1513
x
1614
} else {

exercises/lifetimes/lifetimes2.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
77
// hint.
88

9-
// I AM NOT DONE
10-
119
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
1210
if x.len() > y.len() {
1311
x
@@ -18,10 +16,8 @@ fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
1816

1917
fn main() {
2018
let string1 = String::from("long string is long");
21-
let result;
22-
{
23-
let string2 = String::from("xyz");
24-
result = longest(string1.as_str(), string2.as_str());
25-
}
19+
let string2 = String::from("xyz");
20+
let result = longest(string1.as_str(), string2.as_str());
21+
2622
println!("The longest string is '{}'", result);
2723
}

exercises/lifetimes/lifetimes3.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
9-
10-
struct Book {
11-
author: &str,
12-
title: &str,
8+
struct Book<'a> {
9+
author: &'a str,
10+
title: &'a str,
1311
}
1412

1513
fn main() {

0 commit comments

Comments
 (0)