thanks for all your replies. I understand that zero has a specific meaning to addition, and as well as multiplication, but for some reason does not require the mul trait.
implementing default sounds like a reasonable solution for my case. I initially wanted to implement zero for my matrix4x4. I haven't implemented add as I don't think I'm going to be adding matrix so I did not bother. making default return [0...0] would work as well. cheers, Rémi On Wed, Apr 9, 2014 at 5:20 AM, Kevin Ballard <[email protected]> wrote: > On Apr 7, 2014, at 1:02 AM, Tommi Tissari <[email protected]> wrote: > > On 07 Apr 2014, at 08:44, Nicholas Radford <[email protected]> > wrote: > > I think the original question was, why does the zero trait require the add > trait. > > If that was the original question, then my answer would be that > std::num::Zero requires the Add trait because of the way it is specified: > "Defines an additive identity element for Self". Then the question > becomes: "why is Zero specified like that?", and I would answer: because > then you can use it in generic algorithms which require their argument(s) > to have an additional identity. > > > If you want a zero value for a type that doesn't support addition, > std::default::Default may be a good choice to use. Semantically, that > actually returns the "default value" for a type instead of the "zero > value", but in a type without addition, how do you define "zero value"? > > -Kevin > > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev > > -- 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
