Generic Traits, Impls, and Slices in Rustlang
9,823
Published 2023-02-22
This trait implementation can panic! Can you fix the panics caused by out of bounds indexing?
GitHub: github.com/rust-adventure/yt-generic-trait-and-imp…
All Comments (21)
-
I was very briefly confused by the name "prefix" when it's more of a subsequence, but other than that it was clear.
-
Note that it's possible to use an associated type instead of a generic trait, which has the benefit of being usable as reference, for instance in binds (besides, there is no alternative for T so the generic is redundant and only gives more work to the compiler). The changes are minor in the code (unfortunately it's not possible to post URLs here), just remove the
after Prefix, add "type Data;" in the trait definition and "Type Data = T;" in the blanket implementation, then replace the remaining "T"s with "Self::Data". -
I felt like big brain rusty kettle after watching this detailed explanation. Thank you!
-
First channel with such a great deal. After seeing this I felt I don't know anything, I have so much to learn in Rust. Long way to go
-
I didn't expect this to make sense but it did after watching it!! thank you!
-
Awesome explanation. Love that you go over everything in detail
-
Thanks. This was a really well done video. Your in depth walk-through of the code and types helped a lot. I also thought your example was perfect to get the point across for understanding generics and traits.
-
Beautiful! Thanks for sharing. Looking forward to more intermediate Rust contents like this. :)
-
Great content, my favorite Rust youtuber right now!
-
Good intro! There really mind blowing things you can done with generics, like instead of defining implementations directly for &[T] from your example we can define one for the types for which Deref coercion to &[T] exists. It is one of the most powerful things in type system and a great way to DRY code as alternative to using macros.
-
Excellent video
-
i love this channel
-
Great walkthrough especially for newbies, like me.
-
really neat, thank you for sharing
-
This is very smart
-
I like how you named the folder "tmmmmp" 😆
-
It seems to me, that if we were looking for a subsequence [3, 4, 5] in [1, 2, 3, 4] your program would panic, because (index + prefix.len()) might be larger than the index of the last element in the original vec.
-
Prefix|T> has to be in the same file (inline or module) to be able call has_prefix ?
-
What extension do you use to hide and show the type in vscode or is it part of vscode rust extension? Thanks 🙏
-
The only drawback of using generics is the rustc monomorphisation process… which takes compilation time as it has to generate functions for every type implementing PartialEq right?