# Impl Add twice?

**URL:** <https://users.rust-lang.org/t/impl-add-twice/22107>\
**Category:** uncategorized\
**Created:** [November 9, 2018, 6:28am UTC](https://users.rust-lang.org/t/impl-add-twice/22107 "2018-11-09T06:28:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon80458984](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anon80458984](https://users.rust-lang.org/u/anon80458984)\
**Post date:** [November 9, 2018, 6:28am UTC](https://users.rust-lang.org/t/impl-add-twice/22107/1 "2018-11-09T06:28:03Z")

</div>

Here is what I have so far:

```rust
#[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?

---

<div class="post-metadata">

**Author:** ![DanielKeep](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/danielkeep/32/1713_2.png) [@DanielKeep](https://users.rust-lang.org/u/DanielKeep)\
**Post date:** [November 9, 2018, 6:42am UTC](https://users.rust-lang.org/t/impl-add-twice/22107/3 "2018-11-09T06:42:31Z")

</div>

```rust
impl Add<f64> for Float2 { ... }

```

---

<div class="post-metadata">

**Author:** ![anon80458984](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anon80458984](https://users.rust-lang.org/u/anon80458984)\
**Post date:** [November 9, 2018, 8:19am UTC](https://users.rust-lang.org/t/impl-add-twice/22107/4 "2018-11-09T08:19:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:50am UTC](https://users.rust-lang.org/t/impl-add-twice/22107/5 "2023-01-12T08:50:39Z")

</div>

Closed on January 12, 2023, 8:50am UTC


