Example of an error when lifetime not specified

This commit is contained in:
Fabian Schmidt
2024-01-23 10:48:58 +01:00
commit a754093bd0
4 changed files with 31 additions and 0 deletions

15
src/main.rs Normal file
View File

@@ -0,0 +1,15 @@
fn main() {
let s1 = "Hello worlc";
let s2 = "Hello";
let result: &str = longest(s1, s2);
println!("The longest string is {result}");
}
fn longest(a: &str, b: &str) -> &str {
if a.len() > b.len() {
a
} else {
b
}
}