This blog post describes how you would achieve this:

http://smallcultfollowing.com/babysteps/blog/2012/10/04/refining-traits-slash-impls/

See the section entitled "What if I want overloading?"


On Sat, Jun 15, 2013 at 5:52 AM, Rémi Fontan <[email protected]> wrote:

> Hi,
>
> I read that rust does not handle function overloading. So I seek your
> advise to how I should be handling the following case.
>
> I have a struct vec2d, which is a 2d vector.  vec2d{x:float, y:float}
>
> I would like to implement the trait Mul such that I can multiply a vector
> by another vector, component by component
>
> let v1: Vec2d = ...;
> let v2: Vec2d = ...;
> v1*v2;
>
> but I also would like to be able to multiply a vec2d with a scalar.
> let v3 = v1*-1f;
>
> I tried implementing the trait Mul twice but the compiler complains. How
> would you do it?
>
> cheers,
>
> Rémi
>
>
> --
> Rémi Fontan : [email protected]
> mobile: +64 21 855 351
> 93 Otaki Street, Miramar 6022
> Wellington, New Zealand
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to