Skip to content

Multiplying only works one direction #20118

Closed
@mdinger

Description

@mdinger

Multiply only works when called directly or when inverted (len * 3.0).

#[deriving(Copy, Show)]
pub struct Len(f64);

impl Mul<Len, Len> for f64 {
    fn mul(self, r: Len) -> Len {
        let Len(right) = r;

        Len(self * right)
    }
}

fn main() {
    let len = Len(12.0);

    // works
    println!("{}", 3.0.mul(len));
    // doesn't
    println!("{}", 3.0 * len);
}

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