diff --git a/src/enums/collections/numeric_array.rs b/src/enums/collections/numeric_array.rs index c3da3d4..b2d4dc1 100644 --- a/src/enums/collections/numeric_array.rs +++ b/src/enums/collections/numeric_array.rs @@ -189,6 +189,33 @@ macro_rules! decimal_to_str { } impl NumericArray { + /// Returns the variant name as a short string, for example "Int32" or "Float64". + pub fn variant_name(&self) -> &'static str { + match self { + #[cfg(feature = "extended_numeric_types")] + NumericArray::Int8(_) => "Int8", + #[cfg(feature = "extended_numeric_types")] + NumericArray::Int16(_) => "Int16", + NumericArray::Int32(_) => "Int32", + NumericArray::Int64(_) => "Int64", + #[cfg(feature = "extended_numeric_types")] + NumericArray::UInt8(_) => "UInt8", + #[cfg(feature = "extended_numeric_types")] + NumericArray::UInt16(_) => "UInt16", + NumericArray::UInt32(_) => "UInt32", + NumericArray::UInt64(_) => "UInt64", + NumericArray::Float32(_) => "Float32", + NumericArray::Float64(_) => "Float64", + #[cfg(feature = "decimal")] + NumericArray::Decimal32(_) => "Decimal32", + #[cfg(feature = "decimal")] + NumericArray::Decimal64(_) => "Decimal64", + #[cfg(feature = "decimal")] + NumericArray::Decimal128(_) => "Decimal128", + NumericArray::Null => "Null", + } + } + /// Returns the logical length of the numeric array. #[inline] pub fn len(&self) -> usize { @@ -1246,41 +1273,14 @@ impl Concatenate for NumericArray { to: "NumericArray", message: Some(format!( "Cannot concatenate mismatched NumericArray variants: {:?} and {:?}", - variant_name(&lhs), - variant_name(&rhs) + lhs.variant_name(), + rhs.variant_name() )), }), } } } -/// Helper function to get the variant name for error messages -fn variant_name(arr: &NumericArray) -> &'static str { - match arr { - #[cfg(feature = "extended_numeric_types")] - NumericArray::Int8(_) => "Int8", - #[cfg(feature = "extended_numeric_types")] - NumericArray::Int16(_) => "Int16", - NumericArray::Int32(_) => "Int32", - NumericArray::Int64(_) => "Int64", - #[cfg(feature = "extended_numeric_types")] - NumericArray::UInt8(_) => "UInt8", - #[cfg(feature = "extended_numeric_types")] - NumericArray::UInt16(_) => "UInt16", - NumericArray::UInt32(_) => "UInt32", - NumericArray::UInt64(_) => "UInt64", - NumericArray::Float32(_) => "Float32", - NumericArray::Float64(_) => "Float64", - #[cfg(feature = "decimal")] - NumericArray::Decimal32(_) => "Decimal32", - #[cfg(feature = "decimal")] - NumericArray::Decimal64(_) => "Decimal64", - #[cfg(feature = "decimal")] - NumericArray::Decimal128(_) => "Decimal128", - NumericArray::Null => "Null", - } -} - // --------------------------------------------------------------------------- // From impls - DecimalArray -> NumericArray // --------------------------------------------------------------------------- diff --git a/src/enums/collections/temporal_array.rs b/src/enums/collections/temporal_array.rs index edeb241..f6735c8 100644 --- a/src/enums/collections/temporal_array.rs +++ b/src/enums/collections/temporal_array.rs @@ -92,6 +92,15 @@ pub enum TemporalArray { } impl TemporalArray { + /// Returns the variant name as a short string, for example "Datetime64". + pub fn variant_name(&self) -> &'static str { + match self { + TemporalArray::Datetime32(_) => "Datetime32", + TemporalArray::Datetime64(_) => "Datetime64", + TemporalArray::Null => "Null", + } + } + /// Returns the logical length of the temporal array. #[inline] pub fn len(&self) -> usize { @@ -225,8 +234,8 @@ impl TemporalArray { to: "TemporalArray", message: Some(format!( "Cannot insert {} into {}: incompatible types", - temporal_variant_name(rhs), - temporal_variant_name(lhs) + rhs.variant_name(), + lhs.variant_name() )), }), } @@ -327,8 +336,8 @@ impl Concatenate for TemporalArray { to: "TemporalArray", message: Some(format!( "Cannot concatenate mismatched TemporalArray variants: {:?} and {:?}", - temporal_variant_name(&lhs), - temporal_variant_name(&rhs) + lhs.variant_name(), + rhs.variant_name() )), }), } @@ -672,15 +681,6 @@ impl DatetimeOps for TemporalArray { } } -/// Helper function to get the variant name for error messages -fn temporal_variant_name(arr: &TemporalArray) -> &'static str { - match arr { - TemporalArray::Datetime32(_) => "Datetime32", - TemporalArray::Datetime64(_) => "Datetime64", - TemporalArray::Null => "Null", - } -} - impl Display for TemporalArray { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { diff --git a/src/enums/collections/text_array.rs b/src/enums/collections/text_array.rs index b19af45..2dfc3b8 100644 --- a/src/enums/collections/text_array.rs +++ b/src/enums/collections/text_array.rs @@ -92,6 +92,27 @@ pub enum TextArray { } impl TextArray { + /// Returns the variant name as a short string, for example "String32" or "Categorical8". + pub fn variant_name(&self) -> &'static str { + match self { + TextArray::String32(_) => "String32", + #[cfg(feature = "large_string")] + TextArray::String64(_) => "String64", + #[cfg(feature = "default_categorical_8")] + TextArray::Categorical8(_) => "Categorical8", + #[cfg(feature = "extended_categorical")] + TextArray::Categorical16(_) => "Categorical16", + #[cfg(any( + not(feature = "default_categorical_8"), + feature = "extended_categorical" + ))] + TextArray::Categorical32(_) => "Categorical32", + #[cfg(feature = "extended_categorical")] + TextArray::Categorical64(_) => "Categorical64", + TextArray::Null => "Null", + } + } + /// Returns the logical length of the text array. #[inline] pub fn len(&self) -> usize { @@ -711,31 +732,11 @@ impl Concatenate for TextArray { to: "TextArray", message: Some(format!( "Cannot concatenate mismatched TextArray variants: {:?} and {:?}", - text_variant_name(&lhs), - text_variant_name(&rhs) + lhs.variant_name(), + rhs.variant_name() )), }), } } } -/// Helper function to get the variant name for error messages -fn text_variant_name(arr: &TextArray) -> &'static str { - match arr { - TextArray::String32(_) => "String32", - #[cfg(feature = "large_string")] - TextArray::String64(_) => "String64", - #[cfg(feature = "default_categorical_8")] - TextArray::Categorical8(_) => "Categorical8", - #[cfg(feature = "extended_categorical")] - TextArray::Categorical16(_) => "Categorical16", - #[cfg(any( - not(feature = "default_categorical_8"), - feature = "extended_categorical" - ))] - TextArray::Categorical32(_) => "Categorical32", - #[cfg(feature = "extended_categorical")] - TextArray::Categorical64(_) => "Categorical64", - TextArray::Null => "Null", - } -}