Commit 9171e73
authored
Semigroup generic over Rhs (#493)
Adds support for implementing semigroup for types that can plus_equals
from another type, for example vectors and slices.
Fixes a bug where the semigroup implementation for `Vec` would add
overhanging elements twice, i.e., `[1,2] + [1,1,1]` would result in
`[2,3,2`] instead of `[2,3,1]`.
This leaves one quirk where `is_zero` does not depend on `Rhs`, so Rust
cannot figure out which implementation to use when two are in scope,
forcing the caller to phrase it as `<R as Semigroup>::is_zero(&value)`.
This only applies if `R` implements `Semigroup + Semigroup<Other>`.
Signed-off-by: Moritz Hoffmann <[email protected]>1 parent b0c8f2a commit 9171e73
1 file changed
+29
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
237 | 251 | | |
238 | 252 | | |
239 | 253 | | |
240 | 254 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | 255 | | |
247 | 256 | | |
248 | 257 | | |
249 | 258 | | |
250 | 259 | | |
251 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
252 | 273 | | |
253 | 274 | | |
254 | 275 | | |
| |||
0 commit comments