← All notes

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

Sources

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

Permanent ID: iil:note:kcgsmtw6

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.},
}

Markdown

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.