great share. Someone needs to come up with a "Patterns" book for rust. It's a unique language This "model with enum" pattern would be one of them, for certain. Option::as_ref() and Result::as_ref() would be another commonly rust pattern not discussed much. It's really a fundamental pattern, yet not discussed much. There's an "enum_dispatch" crate you should look into if not familiar with it. Ties the trait to the enum, that way you still have the benefits of the trait, and it's also fast. Here's a snippet of code from the crate docs #[enum_dispatch] trait KnobControl { //... } #[enum_dispatch(KnobControl)] enum Knob { LinearKnob, LogarithmicKnob, }
True, plus patterns are super fun to explore so it would be an engrossing read. There was a small discussion about patterns yesterday and I think two videos from now I'll talk about this state pattern: mstdn.social/@Mithridates/109448071418032470 Which includes learning more about impl blocks and how they can take generics as well, something else commonly overlooked.
great share.
Someone needs to come up with a "Patterns" book for rust. It's a unique language
This "model with enum" pattern would be one of them, for certain.
Option::as_ref() and Result::as_ref() would be another commonly rust pattern not discussed much. It's really a fundamental pattern, yet not discussed much.
There's an "enum_dispatch" crate you should look into if not familiar with it.
Ties the trait to the enum, that way you still have the benefits of the trait, and it's also fast.
Here's a snippet of code from the crate docs
#[enum_dispatch]
trait KnobControl {
//...
}
#[enum_dispatch(KnobControl)]
enum Knob {
LinearKnob,
LogarithmicKnob,
}
True, plus patterns are super fun to explore so it would be an engrossing read.
There was a small discussion about patterns yesterday and I think two videos from now I'll talk about this state pattern: mstdn.social/@Mithridates/109448071418032470
Which includes learning more about impl blocks and how they can take generics as well, something else commonly overlooked.
Love this, thanks!
Thank you!👍
thank you ❤
Thanks!
Great video!