Repository navigation
Support the assignment operator traits like AddAssign #173
Description
Activity
Yes supporting the assign operators would be great!
Float, mostly used for f32 vs f64 could depend on them?Yeah, I think
FloatandPrimIntcan require this.Assign traits have a problem we need to solve in libstd first I think: There's no
AddAssign<&u32> for u32implementations (and so on) yet. The by reference implementations are needed so that bigint can share the same interface.I think it must be weighed if the op assign traits are not so important that maybe they should be added everywhere.
Would this crate accept pull requests implementing compound assignment operators for individual types (say,
BigInt), or would you want to wait and land a complete set of implementations for all your concrete types at once, for consistency?@bluss started
Complexwith #186, but I haven't given it much thought yet. (sorry!) I guessRatio,BigUint, andBigIntare the only other types to consider, and then decide if we want aNumAssign.Hiding them behind an "opassign" feature seems like a good start though, so we don't even have to raise the rustc baseline. I think it's fine to deal with each type in separate PRs.
Hearing that makes me cautiously optimistic. 😄
There seems to be two issues in this issue (no order)
- Supporting OpAssign for Bigint, complex, and the other number types
- Supporting OpAssign in the numeric traits
I don't think the traits have a nice way to use a crate feature to flip their behavior (would it need adding new traits, like FloatOpAssign or so?)
So, #263 bumped us to Rust 1.8 now...
Reacted by Ivan Ukhov, bluss and Felipe S. S. SchneiderAssign traits have a problem we need to solve in libstd first I think: There's no AddAssign<&u32> for u32 implementations (and so on) yet.
Is there an issue upstream tracking this? I just ran into this today writing a generic factorial function :(
There's actually an open PR right now, rust-lang/rust#41336.
Reacted by Phil Ruffwind and Felipe S. S. SchneiderDoes
AddAssignwork fornum::Float?Adding that constraint to
Floatwould be a breaking change, but you should be able to useFloat + NumAssign.Reacted by bluss and Felipe S. S. SchneiderAdding that constraint to Float would be a breaking change
I worked around this by implementing my own Float trait.
ComplexandBigUintare done, and I'll leave the rest in their separate issues:Reacted by bluss and Felipe S. S. Schneider
These have been recently stabilized in rust-lang/rust#28235. We should at least add support for these to our concrete types.
We may also want to require them in our traits where we already require the basic
Addetc., although I'm not sure if that's too much to impose on outside types implementing our traits. It could instead be something new likeNumAssign: Num + AddAssign + SubAssign + ...We'll have to raise our baseline Rust version to 1.8 (once it's released) to support assignment operators, but this feature may be useful enough to finally justify moving up. That would also enable a few other changes we've had blocked on Rust 1.0.