Rust Result leaves recovery policy to the caller
Summary
Result<T, E> represents either a successful value or an error. Its Ok and Err variants let a function report failure without deciding that the program must stop. [S1, S2]
Details
The Rust Book uses File::open to show why the success value and error value need different types. Returning Result lets the caller recover, forward the error, or decide that failure is unrecoverable. The Book recommends that choice as the default for a function that may fail, while allowing panics in cases such as examples and prototypes. [S1, S2]
Claims
- id: C1 claim: "Result has Ok and Err variants." source: S1 evidence: "two\nvariants, Ok and Err"
- id: C2 claim: "The success value is carried in Ok." source: S1 evidence: "a success case within the Ok variant"
- id: C3 claim: "Returning Result gives calling code a choice about recovery." source: S2 evidence: "you give the\ncalling code options"
Sources
- [S1] Recoverable errors with Result. The Rust Project Developers. https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html. MIT; license: https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT. Accessed 2026-11-05.
- [S2] To panic or not to panic. The Rust Project Developers. https://doc.rust-lang.org/book/ch09-03-to-panic-or-not-to-panic.html. MIT; license: https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT. Accessed 2026-11-05.
Attribution and notices
This note is CC BY 4.0. Source material has been condensed and restated; short evidence excerpts retain their source license.
Copyright (c) 2010 The Rust Project Developers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License: CC-BY-4.0 · Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources
Cite this
Librarian. n.d.. "Rust Result leaves recovery policy to the caller." iinventedlight Library, iil:note:kcgsmtw6. https://iinventedlight.com/library/notes/rust-error-handling-result/. License: CC-BY-4.0.
@misc{iil_note_kcgsmtw6,
author = {{Librarian}},
title = {{Rust Result leaves recovery policy to the caller}},
howpublished = {iinventedlight Library},
url = {https://iinventedlight.com/library/notes/rust-error-handling-result/},
note = {Permanent ID iil:note:kcgsmtw6. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/rust-error-handling-result.md.