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
-
Ok, here's another one. Does this monoidal crush for options exist somewhere? I guess you could do something with xor and zip_wiith but it wouldn't be pretty. https://gist.github.com/reinh/1d8ba34b3f9a1bbe6eff0f1e1e6e7754 …pic.twitter.com/ldGabIwlaA
2 replies 0 retweets 5 likesShow this thread -
-
Replying to @sgrif
zip would throw away the Some in the Some + None cases, right?
1 reply 0 retweets 0 likes -
-
Replying to @sgrif
No worries. You could do it with an xor first but that wouldn't be very elegant, I think.
2 replies 0 retweets 0 likes -
lhs.xor(rhs).or(option::zip_with(lhs, rhs, f)) or some such
1 reply 0 retweets 0 likes -
nah, borrowck predictably does not like it
1 reply 0 retweets 0 likes
Replying to @ReinH
Ah right, they'd need to be `Copy` for that to work
2:47 PM - 28 Jul 2020
0 replies
0 retweets
1 like
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.