Skip to content

Support the assignment operator traits like AddAssign #173

Description

@cuviper

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 Add etc., although I'm not sure if that's too much to impose on outside types implementing our traits. It could instead be something new like NumAssign: 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.

Activity

  1. added this to the v0.2.0 milestone on Mar 1, 2016
  2. bluss commented on Mar 2, 2016

    @bluss
    Contributor

    Yes supporting the assign operators would be great! Float, mostly used for f32 vs f64 could depend on them?

  3. cuviper commented on Mar 2, 2016

    @cuviper
    MemberAuthor

    Yeah, I think Float and PrimInt can require this.

  4. bluss commented on Mar 7, 2016

    @bluss
    Contributor

    Assign 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. 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.

  5. jimblandy commented on Apr 25, 2016

    @jimblandy

    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?

  6. cuviper commented on Apr 25, 2016

    @cuviper
    MemberAuthor

    @bluss started Complex with #186, but I haven't given it much thought yet. (sorry!) I guess Ratio, BigUint, and BigInt are the only other types to consider, and then decide if we want a NumAssign.

    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.

  7. bluss commented on Apr 25, 2016

    @bluss
    Contributor

    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?)

  8. cuviper commented on Feb 10, 2017

    @cuviper
    MemberAuthor

    So, #263 bumped us to Rust 1.8 now...

  9. removed this from the v0.2.0 milestone on Feb 10, 2017
  10. Rufflewind commented on Apr 19, 2017

    @Rufflewind

    Assign 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 :(

  11. cuviper commented on Apr 19, 2017

    @cuviper
    MemberAuthor

    There's actually an open PR right now, rust-lang/rust#41336.

  12. gnzlbg commented on Sep 17, 2017

    @gnzlbg

    Does AddAssign work for num::Float ?

  13. cuviper commented on Sep 17, 2017

    @cuviper
    MemberAuthor

    Adding that constraint to Float would be a breaking change, but you should be able to use Float + NumAssign.

  14. gnzlbg commented on Sep 17, 2017

    @gnzlbg

    Adding that constraint to Float would be a breaking change

    I worked around this by implementing my own Float trait.

  15. cuviper commented on Dec 19, 2017

    @cuviper
    MemberAuthor

    Complex and BigUint are done, and I'll leave the rest in their separate issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions