The magic of Rust's type system

preview_player
Показать описание
For today's video, we dissect a tangled mess and uncover its pitfalls. Let's see how Rust's type system empowers developers to enforce crucial invariants, paving the way for cleaner, safer and more robust software.

Рекомендации по теме
Комментарии
Автор

I haven't heard of "parse, don't validate" before, but I love it

AndrewBrownK
Автор

this aligns perfectly with one of most important software design principles: Make INVALID state UN-REPRESENTABLE.

yarub
Автор

This is the greatest start of a video on any language I have seen. Also...I use Arch, btw. Sic Semper Tyranus!

askholia
Автор

A great example is [u8] and Vec<u8> vs str and String: the only difference is the invariant.

Turalcar
Автор

Excellent. I was just settling down to find out how this Rust "type state" idea I had heard of works and here you are explaining it so clearly, right on cue. Thank you.

Heater-v..
Автор

This jumped on the new level in terms of the video effects and presentation. Wonderful!

linkernick
Автор

Bohdan, thank you for the new video. A very interesting point was made in the second part regarding Struct<Struct> - it looks quite intriguing. I have only two comments: 1) If it's merely a trick example, no problem - it's interesting. However, if the goal was to demonstrate its usage in real applications, I'd like to advise newcomers that in real applications, it's more about meta-programming, and Roles should be at least enums. 2) An "empty" struct() doesn't cost anything, hence there's no need to use PhantomData; PhantomData serves another purpose, as demonstrated in the example.

oneofpro
Автор

I love these kinds of videos, please make more videos with logical errors and it's fix with code examples

prabesshh
Автор

You should include how your request handler can perform the deserialization for you with serde. With that, you can be certain that the handler itself never even accepts an invalid request. Function signatures are one of the strongest forms of documentation

christopher
Автор

great vid!
07:18 => yet I would very much like to see a follow-up vid regarding this `PhantomData` what its uses are (beyond the Rust book if there is info available) and what did you mean exactly with "... to avoid unnecessary allocation."?

chillyvanilly
Автор

Very nice, this feel a lot like "opaque types"

scott
Автор

We can also use a couple of other methods in some languages: 1. Design by contract 2. Inductive types

KamyarInanloo
Автор

Didn't know generics can be used like this in structs 😮

Thank you!

ЕвгенийКрасилов-оо
Автор

Whoa, I bet that change from i32 to u32 makes the code riskier financially.

ariaden
Автор

6:15 When you need to parse a struct from string you should implement a FromStr trait instead. If you impelement FromStr, you can then do string.parse::<YourType>(), like you can do with numbers string.parse::<i32>(). Similar to how you should implement From trait for conversion between other types, because you also get Into for free.

KPidS
Автор

Great video! 🙌 Would love more like this where you go through best practices with examples

tt
Автор

checked_sub is also useful to make that withdraw function.

VictorGamerLOL
Автор

Nice, I would love to see more videos about type-driven design

LageAfonso
Автор

> bank account cannot be less than zero
damn I wish

valhalla_dev
Автор

Thank you for the video. Most of these principles can be used in most languages, it's a shame that they aren't popular amongst other developers.

HumanoidTyphoon