Skip to content

Implement std::ops traits to return arbitrary output defined as associated type #7482

@ironcev

Description

@ironcev

When std::ops traits were originally defined, we didn't support associated types. Therefore, all traits, like Add or Sub were defined as, e.g.:

pub trait Add {
    fn add(self, rhs: Self) -> Self;
}

This restricts us in API flexibility. E.g., in std::time::Time, adding Time and Duration requires having add on impl Time.

The proposal is to migrate to Rust-like traits that have the result type specified as associated type. E.g.:

pub trait Add<Rhs> {
    type Output;

    fn add(self, rhs: Rhs) -> Self::Output;
}

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