Impl Add twice?


#1

Here is what I have so far:

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Float2 {
    pub x: f32,
    pub y: f32,
}

impl Add for Float2 {
    type Output = Float2;
    fn add (self, rhs: Float2) -> Float2 {
        Float2 {
            x: self.x + rhs.x,
            y: self.y + rhs.y,
        }
    }
}

This allows Float2 + Float2.

Now, I would also like to implement Float2 + f32, returning Float2, by adding the scalar to both the x & y components.

Is this possible?


#3
impl Add<f64> for Float2 { ... }

#4

@DanielKeep :lol. Thanks! I had actually done this before, but the “Add example” I was reading didn’t specify the and I forgot it could be specified.