diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-01-20 20:04:28 -0330 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-01-20 20:04:28 -0330 |
| commit | 3a1e9d081cc299a0ce3e950282464986a36376d9 (patch) | |
| tree | 1f01505157643ad9b42fd0fc3006126d6e524838 /src/volume/unit.rs | |
| parent | 413608ea229f0adec21feb27501178ccadd47844 (diff) | |
| download | volute-3a1e9d081cc299a0ce3e950282464986a36376d9.zip | |
refactor volume module
Diffstat (limited to 'src/volume/unit.rs')
| -rw-r--r-- | src/volume/unit.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/volume/unit.rs b/src/volume/unit.rs new file mode 100644 index 0000000..1b542d3 --- /dev/null +++ b/src/volume/unit.rs @@ -0,0 +1,27 @@ +use std::fmt::{self, Display, Formatter}; + +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] +pub enum Unit { + CubicMetre, + #[default] + Litre, + CubicCentimetre, +} + +impl Unit { + pub const ALL: [Self; 3] = [Self::CubicMetre, Self::Litre, Self::CubicCentimetre]; +} + +impl Display for Unit { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + Self::CubicMetre => "m³", + Self::Litre => "L", + Self::CubicCentimetre => "cc", + } + ) + } +} |