4 levels of Rust error handling

  Рет қаралды 7,978

timClicks

timClicks

Күн бұрын

Strengthen your code one level at a time. Rust's errors can be confusing. Learn how to start with an easy path and grow as you knowledge increases. This video was produced first for patrons / timclicks
📚 Resources:
// Docs
- Error Handling in Rust - A Deep Dive www.lpalmieri.com/posts/error...
- Error Handling in Rust with Jane Lasore-Lusby rustacean-station.org/episode...
- Error Handling in Rust (old! this one is how I learned!) blog.burntsushi.net/rust-erro...
// Slides
docs.google.com/presentation/...
// Crates
- crates.io/crates/thiserror
- crates.io/crates/eyre
- crates.io/crates/anyhow
🦀 Rust resources:
- Rust Documentation: doc.rust-lang.org/book/
- Rust Playground: play.rust-lang.org/
- Rust in Action (Tim's book!) mng.bz/4MlD
- How to Learn Rust (online course!) learning.accelerant.dev/how-t...
👋 Connect with Tim:
- Twitter: / timclicks
- GitHub: github.com/timClicks
- Mastodon: mastodon.nz/@timClicks
- DEV: dev.to/timclicks/
- Patreon (extra learning materials) / timclicks
Timeline
00:00:00 Introduction
00:01:04 Personal story about learning Rust error handling
00:04:39 Combing errors
00:05:18 Using std::error:Error trait objects
00:08:20 Programmer's view of an error
00:09:40 Type system's view of an error
00:11:32 What is a Result?
00:14:12 Individual modules/crates often define their own Error types
00:16:15 Level 1: Ignore Results
00:17:10 Using unwrap()
00:18:35 Using expect()
00:19:50 Assigning to underscore (_)
00:24:18 Level 2: Return strings as errors
00:25:15 Converting errors with map_err
00:26:40 Defining a function with String as an error type
00:31:34 Level 3: use enums as errors
00:37:20 Why bother to define a custom error type
00:41:50 Level 4: use crates to help
🔔 Subscribe to the channel and click the bell icon to stay updated with the latest videos and live streams from timClicks: kzbin.info?sub...
👍 Like this video if you found it helpful, and share it with your friends who are also interested in Rust programming.

Пікірлер: 13
@JorgetePanete
@JorgetePanete 10 ай бұрын
Some video editing to shorten the video would be very useful
@ekarademir
@ekarademir 11 ай бұрын
Thank you for this video. I just wanted to add, another advantage of using a crate level Error enum is that if you are emitting the errors in different ways, like printing out, or returning as a server response, or pushing into a central system, your extra work would be just implementing conversions to that enum.
@timClicks
@timClicks 11 ай бұрын
Excellent point. Thank you for adding your thoughts.
@agustindiaz3361
@agustindiaz3361 4 ай бұрын
This is awesome! This kind of high quality, advanced topics in rust is really absent in youtube. Thanks for sharing it :D
@pyprem
@pyprem 5 ай бұрын
There is some confusion at 25:17. However, to make this idea work you can do it like this: `.map_err(|_err| "could not create file")?;`, i.e. `map_err` returns the value contained in the Err variant, not the whole variant itself.
@nubunto
@nubunto 2 ай бұрын
came here to say this. there's a confusion between the Result type and the Err variant, which is common!
@bakhtiyargarashov805
@bakhtiyargarashov805 11 ай бұрын
Going through the Rust learning journey with you is amazing. Thanks for that.
@nscheer
@nscheer 5 ай бұрын
Really enjoyed your content! One thing: The video would be way nicer to watch without all the „ehem“ and „aahmm“ - it is worth it to train and let there be just some silence between the words 😊
@timClicks
@timClicks 5 ай бұрын
Thanks for the advice. You'll find that more recent videos of mine are much more polished
@pmcgee003
@pmcgee003 5 ай бұрын
unwrap .. because Result should be understood as a functor / monad
@mustafazakiassagaf1757
@mustafazakiassagaf1757 11 ай бұрын
hey it would be nice if you provide timestamps for longer video like this. other than that this is a good video with good story telling 💪
@timClicks
@timClicks 11 ай бұрын
Done :)
@user-kr9on5rw6q
@user-kr9on5rw6q 11 ай бұрын
Привет я на этом канале сново увидел шедевр это видео прекрасно как и остальные
Rust Error Handling - Best Practices
21:33
Jeremy Chone
Рет қаралды 11 М.
Tim McNamara - 4 levels of error handling
34:49
Rust Nation UK
Рет қаралды 5 М.
когда достали одноклассники!
00:49
БРУНО
Рет қаралды 2,1 МЛН
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 10 МЛН
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 717 М.
ELE QUEBROU A TAÇA DE FUTEBOL
00:45
Matheus Kriwat
Рет қаралды 16 МЛН
PC Matic Home Testimonial - Buzz
2:12
PC Matic
Рет қаралды 1
Rust 1.77.0: 70 highlights in 30 minutes
30:46
Nathan Stocks
Рет қаралды 8 М.
Async Rust Is A Bad Language | Prime Reacts
28:46
ThePrimeTime
Рет қаралды 84 М.
Simple error handling in Rust
23:46
Let's Get Rusty
Рет қаралды 30 М.
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 124 М.
UUID v7 vs. v4 + Rust Programming Examples
19:41
Jeremy Chone
Рет қаралды 13 М.
Stop writing Rust
9:41
No Boilerplate
Рет қаралды 262 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 90 М.
XL-Power Best For Audio Call 📞 Mobile 📱
0:42
Tech Official
Рет қаралды 772 М.
📱 SAMSUNG, ЧТО С ЛИЦОМ? 🤡
0:46
Яблочный Маньяк
Рет қаралды 1,7 МЛН
👎Главный МИНУС планшета Apple🍏
0:29
Demin's Lounge
Рет қаралды 482 М.
ПК с Авито за 3000р
0:58
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,4 МЛН
Kalem ile Apple Pen Nasıl Yapılır?😱
0:20
Safak Novruz
Рет қаралды 1,1 МЛН