From b16b909074691c5d528774827b43c66cefc5f865 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 19 Jan 2023 14:40:59 -0330 Subject: use Volume in text_input widget --- src/volume.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/volume.rs') diff --git a/src/volume.rs b/src/volume.rs index ea78938..087676c 100644 --- a/src/volume.rs +++ b/src/volume.rs @@ -1,12 +1,24 @@ use std::ops::Mul; -trait Volume { +pub trait Volume { /// Returns the volume in SI units (cubic metres). fn si(self) -> CubicMetre; + + fn set(&mut self, val: f64); } -#[derive(Debug, PartialEq)] -struct CubicMetre(f64); +#[derive(Debug, Default, PartialEq)] +pub struct CubicMetre(f64); + +impl Volume for CubicMetre { + fn si(self) -> CubicMetre { + self + } + + fn set(&mut self, val: f64) { + self.0 = val; + } +} #[derive(Debug, PartialEq)] struct Litre(f64); @@ -15,6 +27,10 @@ impl Volume for Litre { fn si(self) -> CubicMetre { CubicMetre(self.0 * 10_f64.powf(-3.)) } + + fn set(&mut self, val: f64) { + self.0 = val + } } impl From for Litre { -- cgit v1.2.3