4 ms·
This must be common, I just bombed a leetcode (tm) interview where I was asked to write code to share a method between two structs using traits in Rust without
by alexfromapex 4y ago
This must be common, I just bombed a leetcode (tm) interview where I was asked to write code to share a method between two structs using traits in Rust without duplicating code. I couldn't remember a time I'd ever seen it done with generics so I tried to find it in the documentation but nothing. I looked up the solution after and it is not possible without writing a macro which is metaprogramming and seems like a poor way to assess how I'd perform writing Rust on a daily basis when I only had ~20 minutes to do it and was transparent that I am still learning the more advanced concepts. There were other red flags I ignored in the interview process, I look at it as a bullet dodged.
- deleted 4y ago[deleted]
- Brentward 4y agoCan't you just provide a default implementation of the method on the trait itself? Unless there are more requirements I'm not parsing from what you wrote, that seems to do exactly what they wanted.
- saghm 4y agoYeah, I'm not sure I fully understand as well. The only thing I can think of is that the trait was supposed to be from outside the crate (i.e. not modifyable), but then then, I'm not sure why writing a function that was generic over T: ThatTrait that took an instance as a parameter (or even `impl ThatTrait`) wouldn't work
- throwaway1777 4y agoThat is not really a leetcode-style interview question. Leetcode focuses on DSA questions not language knowledge.
- ummonk 4y agoWhat they’re describing is leetcode style problems that require the coder to use an abstract high level language that makes coding easy. What you’re describing is the opposite - some kind of esoteric question related to a specific language.