Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Lifetimes | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 24 of 50

·rust

Lifetimes

20 minutes

Course progress48%

Lifetimes

Lifetimes ensure that references are valid for as long as they are used.

fn longest<'a>(a: &'a str, b: &'a str) -> &'a str {
     a.() > b.() { a }  { b }
}

 () {
      = \
if
len
len
else
fn
main
let
s1
"short\"; let s2 = \"much longer string\"; let result = longest(s1, s2); println!(\"Longest: {}\", result); }
Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities
Previous lessonGenericsContinue to lesson 25Modules and PackagesBack to Rust Fundamentals curriculum