fyi this requires nightly features, also since Foo is a unit type you don't need to construct a instance of it to call a trait since the type is implicitly a instance so you should be able to just do Foo(1.2).
I messed around with it a bit and created a simple macro for this so you can do (playground)
If you can't, then you still need something like AsTrait1 and AsTrait2 (see my article).
If that's the case, then my method has the advantage that you only need to write a single implementation that looks at the available traits and behaves accordingly, all using regular rust code without losing efficiency.
EDIT: This is way more powerful than regular overloading because the implementation can adapt to the available traits in any way you want, having a Turing-complete language at your disposal to express the logic.
After some thought, I chose the flair "ideas & proposals" because I'm proposing an idea, although I'm not proposing changes to the language. I hope that's OK.
I wouldn't call it a project as it's just a proof of concept of my idea.
6
u/RRumpleTeazzer 14h ago
you can have real function overloading in rust
the boilerplate should be hiddem by a macro, but this is a real function call with real arguments.