Compare commits

...

3 Commits

Author SHA1 Message Date
Fabian Schmidt
7141085747 Simplified example with lifetimes specified 2024-01-23 11:14:44 +01:00
Fabian Schmidt
fc13310be8 Add Readme 2024-01-23 11:10:54 +01:00
Fabian Schmidt
ae27ad2db2 Example with lifetimes specified 2024-01-23 11:00:39 +01:00
2 changed files with 12 additions and 1 deletions

11
Readme.md Normal file
View File

@ -0,0 +1,11 @@
# Small project to somewhat better understand lifetimes.
This small project aims to help understanding how lifetimes work in rust a little better.
Swap branches to see difference without specifying lifetimes, with lifetimes and then a simplified version.
# youtube
Heavily inspired by the following video: https://www.youtube.com/watch?v=gRAVZv7V91Q

View File

@ -6,7 +6,7 @@ fn main() {
println!("The longest string is {result}");
}
fn longest(a: &str, b: &str) -> &str {
fn longest<'a>(a: &'a str, b: &'a str) -> &'a str {
if a.len() > b.len() {
a
} else {