Skip to content
Learn Netverks

Lesson

Step 21/36 58% through track

result-option

Result and Option

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

This lesson

This lesson teaches Result and Option: the syntax, APIs, and habits you need before advancing in Rust.

Result and Option replace exceptions—explicit error paths are idiomatic and required in production Rust.

You will apply Result and Option 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).

When you can explain the previous lesson's ideas without copying starter code.

Option<T> models absence (None) or presence (Some). Result<T, E> models success (Ok) or failure (Err)—Rust's alternative to null and exceptions.

Option

fn maybe() -> Option<i32> { Some(42) }

Result

fn parse_n(s: &str) -> Result<i32, std::num::ParseIntError> {
    s.parse()
}

Important interview questions and answers

  1. Q: Option vs null?
    A: Compiler forces handling None—no silent null dereference.

Self-check

  1. What variants does Result have?
  2. When use Option vs Result?

Pitfall: Do not unwrap() in production paths—handle None and Err or propagate with ?.

Interview prep

Option vs Result?

Option models optional values (Some/None); Result models recoverable errors (Ok/Err).

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

  • unwrap danger?
  • ? operator?

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