summaryrefslogtreecommitdiff
path: root/exercises/16_lifetimes
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-17 23:34:27 +0200
committermo8it <mo8it@proton.me>2024-04-17 23:34:27 +0200
commit2f810a4da67233716ad93e00afff6e8b260f4807 (patch)
treef5a33357141d25d08b6726910efe33f2338b9cdb /exercises/16_lifetimes
parentcb9f1ac9ce3c834b0cca964b6809b74508f80b54 (diff)
Clean up and unify exercises
Diffstat (limited to 'exercises/16_lifetimes')
-rw-r--r--exercises/16_lifetimes/lifetimes1.rs5
-rw-r--r--exercises/16_lifetimes/lifetimes2.rs5
-rw-r--r--exercises/16_lifetimes/lifetimes3.rs10
3 files changed, 4 insertions, 16 deletions
diff --git a/exercises/16_lifetimes/lifetimes1.rs b/exercises/16_lifetimes/lifetimes1.rs
index 4f544b4..d34f3ab 100644
--- a/exercises/16_lifetimes/lifetimes1.rs
+++ b/exercises/16_lifetimes/lifetimes1.rs
@@ -1,12 +1,7 @@
-// lifetimes1.rs
-//
// The Rust compiler needs to know how to check whether supplied references are
// valid, so that it can let the programmer know if a reference is at risk of
// going out of scope before it is used. Remember, references are borrows and do
// not own their own data. What if their owner goes out of scope?
-//
-// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
-// hint.
fn longest(x: &str, y: &str) -> &str {
if x.len() > y.len() {
diff --git a/exercises/16_lifetimes/lifetimes2.rs b/exercises/16_lifetimes/lifetimes2.rs
index 33b5565..6e329e6 100644
--- a/exercises/16_lifetimes/lifetimes2.rs
+++ b/exercises/16_lifetimes/lifetimes2.rs
@@ -1,10 +1,5 @@
-// lifetimes2.rs
-//
// So if the compiler is just validating the references passed to the annotated
// parameters and the return type, what do we need to change?
-//
-// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
-// hint.
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
diff --git a/exercises/16_lifetimes/lifetimes3.rs b/exercises/16_lifetimes/lifetimes3.rs
index de6005e..9b631ca 100644
--- a/exercises/16_lifetimes/lifetimes3.rs
+++ b/exercises/16_lifetimes/lifetimes3.rs
@@ -1,9 +1,4 @@
-// lifetimes3.rs
-//
// Lifetimes are also needed when structs hold references.
-//
-// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
-// hint.
struct Book {
author: &str,
@@ -13,7 +8,10 @@ struct Book {
fn main() {
let name = String::from("Jill Smith");
let title = String::from("Fish Flying");
- let book = Book { author: &name, title: &title };
+ let book = Book {
+ author: &name,
+ title: &title,
+ };
println!("{} by {}", book.title, book.author);
}