> 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. 

> And it's a valid question. What does saying a value can have a zero value 
> have to do with adding numbers.
> 
> In other words, it is possible for something to have a zero value without 
> requiring addition, so why does the Zero trait not reflect this.
> 
>> On 6 Apr 2014 12:29, "Tommi" <[email protected]> wrote:
>> The tutorial (17.7) says the following:
>> "We can write a trait declaration that inherits from other traits, called 
>> supertraits. Types that implement a trait must also implement its 
>> supertraits.
>> 
>> Since num::Zero inherits from Add<Self, Self>, you must implement it (the 
>> supertrait) also.
>> 
>>> On 2014-06-04, at 11:25, Rémi Fontan <[email protected]> wrote:
>>> 
>>> Hi,
>>> 
>>> when compiling following code I get following error:
>>> use std::num;
>>> struct vec2d { a:f32, b:f32 }
>>> impl num::Zero for vec2d {
>>>     fn zero() -> vec2d {
>>>         vec2d{a:0.0, b:0.0}
>>>     }
>>> 
>>>     fn is_zero(&self) -> bool {
>>>         self.a==0.0 && self.b==0.0
>>>     }
>>> }
>>> 
>>> 
>>> 
>>> test.rs:4:1: 12:2 error: failed to find an implementation of trait 
>>> std::ops::Add<vec2d,vec2d> for vec2d
>>> test.rs:4 impl num::Zero for vec2d {
>>> test.rs:5     fn zero() -> vec2d {
>>> test.rs:6         vec2d{a:0.0, b:0.0}
>>> test.rs:7     }
>>> test.rs:8 
>>> test.rs:9     fn is_zero(&self) -> bool {
>>> 
>>> 
>>> Would you know why the Add trait seems to be a requirement for implementing 
>>> the zero trait.
>>> 
>>> cheers,
>>> 
>>> Rémi
>>> 
>>> 
>>> _______________________________________________
>>> 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
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to