Skip to content
Learn Netverks

Lesson

Step 16/36 44% through track

lifetimes-intro

Lifetimes intro

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

An orientation to the Rust track—how the server playground works, core vocabulary, and what you will practice next.

You need a clear map of the Rust track so ownership, borrowing, and the borrow checker do not feel like magic.

You will apply Lifetimes intro in contexts like: Infrastructure CLIs, proxies, game engines, blockchain nodes, and latency-sensitive backends.

Write Rust with fn main(), click Run on server—the dev runner compiles main.rs with rustc and runs the binary; fix borrow errors from stderr (requires Rust toolchain; LEARNING_RUNNER_ENABLED=true). Also read the interview prep blocks.

After HTML fundamentals and basic programming concepts—before or alongside SQL.

Lifetimes annotate how long references are valid. The compiler uses them to reject dangling references—often inferred without explicit syntax in simple code.

When explicit lifetimes appear

fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() { x } else { y }
}

Important interview questions and answers

  1. Q: What problem do lifetimes solve?
    A: Ensure references never outlive the data they borrow—no dangling pointers in safe Rust.
  2. Q: Must every reference be annotated?
    A: No—lifetime elision covers common patterns; explicit when the compiler cannot infer ties.

Self-check

  1. What does 'a represent?
  2. Can a function return a reference to a local variable?

Tip: Most playground code needs no explicit lifetimes—add 'a when returning references tied to parameters the compiler cannot infer.

Interview prep

What are lifetimes for?

They tie reference validity to borrowed data so references never outlive what they point to.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Lifetime annotation why?
  • Elision rules?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump