Skip to content

Commit 832d268

Browse files
committed
syntax: add unit for density
1 parent c02415a commit 832d268

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lang/syntax/literal/units.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub enum Unit {
9292
Milliliter,
9393
/// Microliter
9494
Microliter,
95+
96+
/// Density
97+
KilogramPerMeter2,
9598
}
9699

97100
impl std::fmt::Display for Unit {
@@ -145,6 +148,9 @@ impl std::fmt::Display for Unit {
145148
Self::Centiliter => write!(f, "cl"),
146149
Self::Liter => write!(f, "l"),
147150
Self::Microliter => write!(f, "µl"),
151+
152+
// Density
153+
Self::KilogramPerMeter2 => write!(f, "kg/m2"),
148154
}
149155
}
150156
}
@@ -181,6 +187,7 @@ impl Unit {
181187
| Self::Centiliter
182188
| Self::Milliliter
183189
| Self::Microliter => Type::Volume,
190+
Self::KilogramPerMeter2 => Type::Density,
184191
}
185192
}
186193
/// Normalize value to mm, rad or gram
@@ -232,6 +239,9 @@ impl Unit {
232239
Self::Centiliter => x * 10_000.0_f64,
233240
Self::Milliliter => x * 1_000.0_f64,
234241
Self::Microliter => x * 1_000_000.0_f64,
242+
243+
// Densities
244+
Self::KilogramPerMeter2 => 1_f64,
235245
}
236246
}
237247
}

0 commit comments

Comments
 (0)