Hello Rust friends. Is it bad to implement Add and then use this boilerplate for AddAssign? impl AddAssign for Foo { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; } }
-
Show this thread
-
Replying to @ReinH
I don't see why it would be. The docs show this happening in it's example for the trait
1 reply 0 retweets 2 likes -
Replying to @mgattozzi
Seems a bit odd that you don't get AddAssign for free by implementing Add. I don't think there would be a problem with conflicting implementations if you needed to define it concretely?
1 reply 0 retweets 1 like -
Replying to @ReinH
It's not like it has an Add trait bound requirement that allows that to happen. There's also the fact you can add different types together but not with add assign
2 replies 0 retweets 1 like -
Replying to @mgattozzi @ReinH
But it could just be design overnight and then things stabilized but I couldn't give you an exact reason
1 reply 0 retweets 0 likes -
Replying to @mgattozzi
Yeah, I wonder if it would be possible to derive AddAssign for types that implement Add.
1 reply 0 retweets 1 like
I'd be shocked if there isn't already a crate for this. I'll be one or all of the "derive more things" crates has this built in
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.