Example of an error when lifetime not specified
This commit is contained in:
15
src/main.rs
Normal file
15
src/main.rs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user