Example of an error when lifetime not specified
This commit is contained in:
commit
a754093bd0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lifetimes"
|
||||||
|
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "lifetimes"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user