Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement std::ops::*Assign traits for slices #45235
Comments
This comment has been minimized.
This comment has been minimized.
|
On the one hand, I can definitely see the usefulness. On the other hand, there are some questions that I think need considered. In
|
This comment has been minimized.
This comment has been minimized.
I personally think it should simply panic if
As I wrote in the implementation I think we should use
Yes, because
It should not, and in the implementation which I presented it does not. It's a fully working code, copy pasted from my local copy of the repository.
Unfortunately I can't answer this question. |
This comment has been minimized.
This comment has been minimized.
That's the main reason that using Either of these would allow dropping the |
This comment has been minimized.
This comment has been minimized.
|
It could be definitely nice to remove Also if I am not mistaken After some thought, it seems that proposed implementation could brake 3rd party code, e.g. in case if crate defines some type |
kennytm
added
C-feature-request
T-libs
labels
Oct 13, 2017
This comment has been minimized.
This comment has been minimized.
|
The behavior of panicking on a size mismatch makes me uneasy about adding these impls. In any case, it seems like there is some design work to figure out still, and plenty of tradeoffs. I would prefer for this feature to go through the RFC process if anyone feels motivated to put together a writeup of the tradeoffs, alternative designs, and concrete proposal. |
newpavlov commentedOct 12, 2017
Quite often I need to xor two slices, but I can't write
buf1 ^= buf2;asBitXorAssignis not implemented for&[u8]and it's quite an unpleasant papercut for me. I couldn't find a good reason why it was not done, so I would like to suggest to add generic implementations ofops::*Assigntraits.It can be done as follows:
Click to expand
I am not sure about second impl in the macro, but I guess in some cases it could be convenient to write
buf += 4;instead of an explicit loop.I can create PR if there is no arguments against this addition.