D-like Operator Overloading


#1

What are the plans for improving Rust’s operator overloading? Specifically in comparison to D’s?

I’m thinking especially in terms of

Further, is there a Rust equivalent of D’s alias this?

These two together makes it very convenient (little code) to create a wrapper type around existing types, that changes only a small amount of the interface. Useful for instance when defining bounded numeric types.


#2

I’m not aware of any plans to change operator overloading. If this is stuff you want, maybe work on writing up an RFC!


#3

Those are interesting features, but I don’t know how they fit in Rust, and every one of them needs a discussion…


#4

Delegation of trait impls would certainly help and it is a generally useful thing, not just for operator overloading.

Maybe it can fit in under Rust’s new productivity goal?


#5

I agree with @bluss that the delta here is in method delegation, not something specific to operator overloading.

I think there’s definitely something we should do here, but I’m uncertain about what exactly. There are several different sorts of delegation users can want (e.g. delegating to a member, delegating a trait method to an inherent method, delegating an inherent method to a trait method) and I think we need a neat & grokkable system for handling it. There’s an RFC, but I think it only deals with ‘composition delegation’ & not the other kinds.


#6

The Deref and DerefMut traits support this functionality.