Skip to content

Commit

Permalink
rust: Add guard clauses section
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed May 30, 2023
1 parent 01c2069 commit fcc9274
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/rust/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ Prefer functions, but use macros if you need:
- `Debugging <https://veykril.github.io/tlborm/decl-macros/minutiae/debugging.html>`__ in *The Little Book of Rust Macros*
- `cargo-expand <https://github.com/dtolnay/cargo-expand>`__

Guard clauses
~~~~~~~~~~~~~

Code with too much indentation is hard to read. One option is to use guard clauses. For example:

.. code-block:: rust
let Some(inner_value) = outer_value else {
return
};
.. code-block:: rust
let inner_value = match outer_value {
Ok(o) => o,
Err(e) => return e,
};
Troubleshooting
---------------

Expand Down

0 comments on commit fcc9274

Please sign in to comment.