rustbites rustbites bite-sized rust tips
Archives About
#020 Sep 11, 2022
option iterator

20. let-else statements

As of 1.65, it is possible to use let statement with a refutable pattern.

1
2
3
4
5
6
7
let result: Result<i32, ()> = Ok(20);

let Ok(value) = result else {
  panic!("Heeeelp!!!");
};

assert_eq!(value, 20);

This post is licensed under CC BY 4.0 by the author.

Share:
← Previous 19. breaking from labeled blocks Next → 21. Zip longest

Trending Tags

Rust Std Iterator Option Iterators Collections Slices Functional Performance Stdlib Arrays Integers Math Parsing Result Strings Vec Concurrency Error-Handling Iter Pattern-Matching Rust-1.95 Algorithms Attributes Closures Enum Hashmap Hints Io Macro Match Overflow Rust-2024 Smart-Pointers Sorting Static Traits Arc Arithmetic Array-Windows Async Atomics Benchmarking Borrow-Checker Box Break Casting Cell Cfg Clippy Closure Combinators Compile-Time Compiler Conditional-Compilation Const Const-Generics Constants Cow Cross-Platform Data-Processing Debugging Default Diagnostics Display Drain Entry Enumerate Error-Messages File-Locking Filter Flatten Float Fn Fnmut Fnonce Fold Formatting From_fn Guards If-Let Impl-Trait Initialization Interior-Mutability Intersperse Lazy Lazylock Let-Chains Lifetime Lifetimes Lints Loop Map Map_while Match-Guards Matching Mem Memory Numerics Optimization Ownership Patterns Peekable Pettern Pipes Position Precision Processes Raw String Rust-1.88 Rust-1.94 Scan Scoped-Threads Slice String Threads Tokio Trait-Objects Try-Fold Type-Inference Type-Safety Unzip Upcasting Utf-8 Validation Vecdeque

Recently updated

#089 89. cold_path — Tell the Compiler Which Branch Won't Happen #090 90. black_box — Stop the Compiler From Erasing Your Benchmarks #088 88. Vec::push_mut — Push and Modify in One Step #087 87. Atomic update — Kill the Compare-and-Swap Loop #085 85. cast_signed & cast_unsigned — Explicit Sign Casting for Integers

About

A collection of bite-sized Rust tips and tricks. Small, focused lessons to help you write better Rust.

info@rustbites.com
rustbites rustbites · 2022—2026
X RSS

This site uses cookies for analytics and ads. Learn more