3 ms·
For addition I can't either, but you could use it to overload multiplication of two (mathematical) vectors to a dot-product impl Mul for Vec2{ type Outpu
by Coding_Cat 12y ago
For addition I can't either, but you could use it to overload multiplication of two (mathematical) vectors to a dot-product
impl Mul for Vec2{
type Output = double;
fn mul(self, other: Vec2) -> Double {
self.0*other.0+self.1*other.1)
}
}
Although I must admit I'm not (yet) sure why you need to explicitly state the output and define it for the function. But I have only just started with Rust.
- Ygg2 12y ago> Although I must admit I'm not (yet) sure why you need to explicitly state the output and define it for the function. But I have only just started with Rust. I generally assume it's because it can't infer the associated type from function signature, for now.
- sanderjd 12y agoA simple example for addition would be adding two u64s and getting a bignum type.