lifetimes done
This commit is contained in:
parent
ec8aefc4b9
commit
1e91ec6f03
|
@ -8,9 +8,8 @@
|
||||||
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// 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() {
|
if x.len() > y.len() {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
||||||
if x.len() > y.len() {
|
if x.len() > y.len() {
|
||||||
|
@ -22,6 +21,6 @@ fn main() {
|
||||||
{
|
{
|
||||||
let string2 = String::from("xyz");
|
let string2 = String::from("xyz");
|
||||||
result = longest(string1.as_str(), string2.as_str());
|
result = longest(string1.as_str(), string2.as_str());
|
||||||
}
|
|
||||||
println!("The longest string is '{}'", result);
|
println!("The longest string is '{}'", result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
struct Book {
|
struct Book<'a> {
|
||||||
author: &str,
|
author: &'a str,
|
||||||
title: &str,
|
title: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Reference in New Issue