My favorite Rust design pattern

preview_player
Показать описание
Today we are discussing one of my favorite Rust design patterns... extension traits! Along the way, we will learn about Rust's unusual orphan rule and a best practice Rust library authors should follow!

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

No arch users were hurt during the making of this video

kchaitanya
Автор

C# extension method has been one of my favorite features, and I am really happy to see it being loved in other mainstream languages. (I do love Rust and Kotlin)

xucongzhan
Автор

I said in a work meeting that I like using "chorno", now I'm having a sit-down with HR 🤷

gpcureton
Автор

I wasn't redirected. I guess my fingerprint is too hardened.

CjqNslXUcM
Автор

Nice! Rust enables extending the standard types without the global "prototype pollution" style problems of JS.

BillieTheGoose
Автор

First time I've heard an explanation of the orphan rule that made sense. Thank you, haha.

johnt
Автор

as an arch user I can tell: my user agent does not contain Arch.

Funnyfacer
Автор

Yes, an extension trait is a very powerful. I wildly used it in Swift and now in Rust;

kamertonaudiophileplayer
Автор

4:24 you graciously flashbanged the shit out of me lmao

gustavoshigueo
Автор

There's a typo at the end, you wrote chorno instead of chrono

coffee-is-power
Автор

Very clear demonstrations of some very cool features of Rust.

orterves
Автор

Thank you for talking about this! I think this trips up allot of people and you explained it nicely.
I had to think about it just recently because someone asked me how you could implement Copy for Rc, exactly this problem.

TheNoirKamui
Автор

Nice one! Didn't know about the blanket implementations. Quite powerful.

flwi
Автор

Extension methods are really common in C# code. Sometimes you'll have a regular old int variable and the autocomplete in visual studio will tell you all the different extension methods that all your various imported libraries have implemented.

CaseyChesshir
Автор

As an Arch user I would appreciate a bigger challenge 😂

be_ncrypted
Автор

Started my pc, went to the website, but nothing. No redirect. Sad :((

Iuigi_t
Автор

Wow, this is really powerful to extend functionality of crates we use and need to customize for our needs. Thanks for sharing!

luiscarlosjayk
Автор

1:00 this isn't what the orphan rule is about. This wouldn't work even without the orphan rule.
The orphan rule is about preventing you from adding unexpected behavior to a foreign type that is defined in a foreign trait.
For example there is the copy trait of the rust std library. You could implement it for any type changing the behavior for the type could result in the type not working like it was designed to.
Or an serializable trait in a serialization crate and a struct with Passwords in another crate that should not be serializable.
The orphan rule prevents a 3rd actor to break the contract or purposely lack of between a trait and a type.

redcrafterlppa
Автор

I now did try to use the extension trait design pattern to to "override" / enhance the .into() method of the Error type to allow for an &String.
I did not succeed. Is this possible ?

michaelschnell
Автор

Could you remove the need for Clone by storing only the hashes rather than the Items?

alexspencer