Skip to content

Commit 3577826

Browse files
committed
Don't allow for multiplying unit types by themselves
The result should actually be the unit type squared, but as this is something we don't have to worry about, let's just disallow it.
1 parent 8c08999 commit 3577826

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/units.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use serde::{Deserialize, Serialize};
44
use std::fmt;
5-
use std::ops::{AddAssign, SubAssign};
5+
use std::ops::{AddAssign, Mul, SubAssign};
66

77
macro_rules! base_unit_struct {
88
($name:ident) => {
@@ -20,12 +20,6 @@ macro_rules! base_unit_struct {
2020
)]
2121
pub struct $name(pub f64);
2222

23-
impl std::ops::Mul<$name> for $name {
24-
type Output = $name;
25-
fn mul(self, rhs: $name) -> $name {
26-
$name(self.0 * rhs.0)
27-
}
28-
}
2923
impl std::ops::Div<$name> for $name {
3024
type Output = Dimensionless;
3125
fn div(self, rhs: $name) -> Dimensionless {
@@ -94,6 +88,14 @@ impl From<Dimensionless> for f64 {
9488
}
9589
}
9690

91+
impl Mul for Dimensionless {
92+
type Output = Dimensionless;
93+
94+
fn mul(self, rhs: Self) -> Self::Output {
95+
Dimensionless(self.0 * rhs.0)
96+
}
97+
}
98+
9799
impl Dimensionless {
98100
/// Raises this dimensionless number to the power of `rhs`.
99101
pub fn powi(self, rhs: i32) -> Self {

0 commit comments

Comments
 (0)