diff options
Diffstat (limited to 'src/types.rs')
| -rw-r--r-- | src/types.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/types.rs b/src/types.rs index 5614ab7..febdace 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,8 @@ use std::fmt; -#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] +#[derive(Copy, Clone, Default, Debug, PartialEq, serde::Serialize, serde::Deserialize)] pub enum FloatPrecision { + #[default] Single, Double, } @@ -33,6 +34,11 @@ impl ScalarType { None } } +impl Default for ScalarType { + fn default() -> Self { + Self::Float(Default::default()) + } +} impl fmt::Display for ScalarType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -91,6 +97,21 @@ impl Type { } } + pub fn upcast_gentype(self, other: Self) -> Result<Self, ()> { + if self == other { + // same scalar or complex type + Ok(self) + } else if Self::Scalar(self.scalar()) == other { + // complex and scalar type + Ok(self) + } else if Self::Scalar(other.scalar()) == self { + // complex and scalar type + Ok(other) + } else { + Err(()) + } + } + pub fn pick(ui: &mut egui::Ui) -> Option<Self> { let mut result: Option<Self> = ScalarType::pick(ui).map(Self::Scalar); @@ -149,6 +170,12 @@ impl fmt::Display for Type { } } +impl Default for Type { + fn default() -> Self { + Self::Scalar(Default::default()) + } +} + /// a single concrete type signature for a function #[derive(PartialEq, Debug)] pub struct TypeSignature { |
