This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new d52cae0df Remove ArrowNativeType: FromStr (#2775)
d52cae0df is described below

commit d52cae0df1d7ba651d2c9a7d4904666363f40a76
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Sat Sep 24 17:26:24 2022 +0100

    Remove ArrowNativeType: FromStr (#2775)
    
    * Remove ArrowNativeType: FromStr
    
    * Format
---
 arrow-buffer/src/native.rs      | 10 +--------
 arrow/src/lib.rs                |  1 +
 arrow/src/util/reader_parser.rs | 47 +++++++++++++++++++----------------------
 3 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/arrow-buffer/src/native.rs b/arrow-buffer/src/native.rs
index d8431953c..90855872d 100644
--- a/arrow-buffer/src/native.rs
+++ b/arrow-buffer/src/native.rs
@@ -44,15 +44,7 @@ mod private {
 ///
 /// Due to the above restrictions, this trait is sealed to prevent accidental 
misuse
 pub trait ArrowNativeType:
-    std::fmt::Debug
-    + Send
-    + Sync
-    + Copy
-    + PartialOrd
-    + std::str::FromStr
-    + Default
-    + private::Sealed
-    + 'static
+    std::fmt::Debug + Send + Sync + Copy + PartialOrd + Default + 
private::Sealed + 'static
 {
     /// Convert native type from usize.
     #[inline]
diff --git a/arrow/src/lib.rs b/arrow/src/lib.rs
index 5cc264b13..ce171ec86 100644
--- a/arrow/src/lib.rs
+++ b/arrow/src/lib.rs
@@ -117,6 +117,7 @@
 //! fn parse_to_primitive<'a, T, I>(iter: I) -> PrimitiveArray<T>
 //! where
 //!     T: ArrowPrimitiveType,
+//!     T::Native: FromStr,
 //!     I: IntoIterator<Item=&'a str>,
 //! {
 //!     PrimitiveArray::from_iter(iter.into_iter().map(|val| 
T::Native::from_str(val).ok()))
diff --git a/arrow/src/util/reader_parser.rs b/arrow/src/util/reader_parser.rs
index 6b6f24f82..91b362df8 100644
--- a/arrow/src/util/reader_parser.rs
+++ b/arrow/src/util/reader_parser.rs
@@ -21,9 +21,7 @@ use crate::datatypes::*;
 /// Specialized parsing implementations
 /// used by csv and json reader
 pub(crate) trait Parser: ArrowPrimitiveType {
-    fn parse(string: &str) -> Option<Self::Native> {
-        string.parse::<Self::Native>().ok()
-    }
+    fn parse(string: &str) -> Option<Self::Native>;
 
     fn parse_formatted(string: &str, _format: &str) -> Option<Self::Native> {
         Self::parse(string)
@@ -42,21 +40,23 @@ impl Parser for Float64Type {
     }
 }
 
-impl Parser for UInt64Type {}
-
-impl Parser for UInt32Type {}
-
-impl Parser for UInt16Type {}
-
-impl Parser for UInt8Type {}
-
-impl Parser for Int64Type {}
-
-impl Parser for Int32Type {}
-
-impl Parser for Int16Type {}
-
-impl Parser for Int8Type {}
+macro_rules! parser_primitive {
+    ($t:ty) => {
+        impl Parser for $t {
+            fn parse(string: &str) -> Option<Self::Native> {
+                string.parse::<Self::Native>().ok()
+            }
+        }
+    };
+}
+parser_primitive!(UInt64Type);
+parser_primitive!(UInt32Type);
+parser_primitive!(UInt16Type);
+parser_primitive!(UInt8Type);
+parser_primitive!(Int64Type);
+parser_primitive!(Int32Type);
+parser_primitive!(Int16Type);
+parser_primitive!(Int8Type);
 
 impl Parser for TimestampNanosecondType {
     fn parse(string: &str) -> Option<i64> {
@@ -85,13 +85,10 @@ impl Parser for TimestampSecondType {
     }
 }
 
-impl Parser for Time64NanosecondType {}
-
-impl Parser for Time64MicrosecondType {}
-
-impl Parser for Time32MillisecondType {}
-
-impl Parser for Time32SecondType {}
+parser_primitive!(Time64NanosecondType);
+parser_primitive!(Time64MicrosecondType);
+parser_primitive!(Time32MillisecondType);
+parser_primitive!(Time32SecondType);
 
 /// Number of days between 0001-01-01 and 1970-01-01
 const EPOCH_DAYS_FROM_CE: i32 = 719_163;

Reply via email to