liveBook · Manning

Todo!

As explained in Learn Rust in a Month of Lunches

todo! is a Rust standard-library macro that marks unfinished code and panics if the marked code is executed.

todo! is a Rust standard-library macro for marking unfinished code. It lets a program compile while you sketch its overall structure, but executing the marked code panics. section 11.2

Compile a partial book program

A function can keep its intended signature while postponing its implementation: fn get_book(book: &Book) -> Option<String> { todo!(); } and fn delete_book(book: &Book) -> Result<(), String> { todo!(); }. The surrounding program can compile and run if neither function is called; the example prints "It's hardcover". The return type still must name a type Rust knows.

Use todo! while prototyping, with these limits:

  • Keep valid function signatures and declared types; todo! does not hide unknown types or invalid surrounding code. section 11.2
  • Treat todo! as temporary: it expands to panic!("not yet implemented") or a formatted equivalent, and is equivalent to unimplemented! for this purpose. section 22.3 section 11.2

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains placement, signatures, runtime panic behavior, formatted messages, and macro expansion, but not compiler internals.
Examples
Uses unfinished book functions, a hardcover match, struct fields, formatted panic messages, and compiler errors for unknown types.
What it assumes
Assumes enough Rust syntax to write functions, return types, structs, and macros; clarifies that referenced types must already exist.
What you can do after
Apply it via Rust syntax to defer implementation while preserving type-checkable program structure and recognizing its runtime panic.
How it connects
Connects todo! with macros, panic!, unimplemented!, function signatures, prototyping, and formatted output.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.