Why can't we implement a trait for a generic T and then for a concrete T in #Rust?

Can't we just resolve to the most concrete implementation? 🤔

#RustLang

@mo8it I believe that feature exists in C++.

... and I'm pretty sure I hate it. It's spooky action at a distance. "Why the hell is this code behaving this way. I'm looking at the trait implementation, it's nothing like what the code is doing... *Oh I see there's another implementation of the trait for a concrete template specialization all the way over here in a different file well I guess my time is worthless then.*

(Note: this wouldn't actually be so bad if C++ had a way to say "For this variable, what function is being called from this line?" But it doesn't, so specialized template implementation suck on toast for discoverability).

@mtomczak I see that it can be confusing, but the language server should be able to resolve to the right implementation, right?

@mo8it Some of the time. We have a huge codebase in a monorepo managed by Bazel rules and it's real easy to push the language server right over trying to understand the whole thing.

I'd say it works about 60% of the time.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.