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 Iterators Collections Option Performance Vec Slices Strings Concurrency Rust-1.95 Result Sync Arrays Error-Handling Ownership Sorting Functional Integers Interior-Mutability Math Mem Parsing Stdlib Hashmap Smart-Pointers Arc Ffi Lazylock Overflow Path Pattern-Matching Rust-1.93 Slice Allocation Async Attributes Btreemap Cell Closures Cow Entry Ergonomics Filesystem Generics Io Iter Rust-1.94 Algorithms Api-Design Arithmetic Atomics Borrow-Checker Debugging Enum Future Hints Impl-Trait Lazy Lazycell Macro Match Maybeuninit Nonzero Oncelock Patterns Peekable Pin Rc Rust-2024 Rwlock Smart-Pointer State-Machine Static Testing Traits Utf-8 Vecdeque Array-Windows Atomic Benchmarking Binary-Heap Binaryheap Bool Box Break Casting Cfg Char Clippy Closure Cmp Collect Combinators Compile-Time Compiler Conditional-Compilation Const Const-Generics Constants Controlflow Conversions Copy Cross-Platform Data-Processing Default Deref Diagnostics Dispatch Display Drain Duration Enumerate Enums Error-Messages File File-Locking Filter Flatten Float Floats Fmt Fn Fnmut Fnonce Fold Formatting From_fn Fs Gotcha Guards If-Let Initialization Inline Intersperse Into-Iter Lazy-Init Lazy-Initialization Let-Chains Lifetime Lifetimes Lints Loop Macros Map Map_while Match-Guards Matching Mem-Replace Memory Mutex Niche Num Numeric Numerics Oncecell Optimization Ord Ordering Panic Panics Pathbuf Pettern Phantom-Data Pin-Project Pipes Position Precision Processes Ranges Raw String Refcell Rust-1.79 Rust-1.88 Rust-1.91 Rust-1.96 Scan Scoped-Threads Search Sort Statics Str String Threads Time Tokio Trait-Objects Try-Fold Type-Inference Type-Safety Types Unicode Unsafe Unsafecell Unzip Upcasting Validation Weak Zero-Sized-Types

Recently updated

#202 202. Arc::clone Is a Refcount Bump, Not a Deep Copy — Share Big Data, Don't Duplicate It #203 203. Peekable::next_if_map — Consume a Token Only If It Parses, Transform in One Step #204 204. take_while / skip_while — Act on the Leading Run, Not Every Match #200 200. #[derive(Copy)] and #[inline] — Make Small Types Free to Pass Around #201 201. or_insert vs or_insert_with — Don't Build a Default You'll Throw Away

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