Skip to content

Numeric types should probably support "reference overloads" for operators. #94

Closed
@sellibitze

Description

@sellibitze

Writing generic code over numeric types is hard in Rust right now. One has to add additional bounds like Clone, Copy or a whole bunch of for<'a> &'a T: for <'b> Add<&'b T, Output=T> bounds (for various combinations of references, non-references and operators) to support "non-consuming" versions of arithmetic operators.

What do you guys and gals think about adding those "non-consuming operators" to the Num trait? I added these kinds of operator implementations for the built-in types in the standard library for that reason in consultation with @aturon . Addings these requirements to the Num trait would make the life of a numeric type provider a little harder but we still have macros that ease the pain. It would be a great benefit for generic numeric code in that "T: Num" is much less noisy than "T: Num + for<'b> Add<&'b T, Output=T> + …` etc.

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